Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to create header file and source file of a .ui file in Qtdesigner?

Tags:

qt

I have an application in which i have a mainwindow.ui file and i create a new designer file dialoge.ui in same application now how i can create source file and header file for dialoge.ui .I am using QtCreater(windows).

I am a beginner in qt , i think there should be a way for the same but i am not getting. Help me. Thanks

like image 805
Qtdesigner Avatar asked Apr 20 '11 09:04

Qtdesigner


4 Answers

You can create source & header out of .ui file externally & then import them into your application(Dont forget to reference then in the .pro file.). Create a executable(.bat or .exe) to execute following commands. Below is the shell script(I am a linux user.)

echo HEADERS 
<path to your uic compiler>/uic -o form.h form.ui 
echo SOURCES 
<path to your uic compiler>/uic -i form.h -o  form.cpp form.ui
like image 101
Preetam Avatar answered Nov 03 '22 13:11

Preetam


For each file somewidget.ui, during the build process ui_somewidget.h and ui_somewidget.cpp will be created. The tool used to generate them is uic. All you have to make sure that the .ui files are added to the .pro file of your project, along with the other source and header files, like this:

 FORMS += somewidget.ui

qmake/make will automatically generate and build the .cpp and .h files for somewidget.ui.

like image 25
Frank Osterfeld Avatar answered Nov 03 '22 12:11

Frank Osterfeld


you can do this:

Save your dialoge.ui file in a directory. Use qmake to create the .pro file (qmake -project), qmake is smart enough to detect the .ui. This will also generate the appropriate makefile rules to invoke uic, Qt's user interface compiler. If you are using visual studio, you can call qmake -tp vc, this will generate a visual studio project, linked and ready to use. The visual studio project will generate a ui_dialoge.h for you, you can copy this to another project and use it in another header file which will use this dialoge.ui

like image 2
Samer Avatar answered Nov 03 '22 12:11

Samer


I'm not sure I've completely understood your question. You have an application developed in QtCreator in which you have 2 .ui files. And you want to generate the corresponding header/source files to these 2 files.

Using QtCreator you don't need to worry about generating header files. This is done automatically. During the build phase, the User Interface Compiler (uic) is called and translates the .xml files into c++ header files.

like image 1
bruno Avatar answered Nov 03 '22 13:11

bruno