running .ui file in qt creator - qt

I created a widget in Qt designer. After generating .ui file , now I want to compile it in qt creator. The .ui file is opened but run, build, debug .etc button are not enabled. How can I run this in qt creator? Creating a project and pasting .ui file into the project directory doesn't work. Thanks.

The ui file must be added to the FORMS section of the .pro file.
FORMS+=yourfile.ui
The build step uses the /bin/uic command in the Qt directory (so you could conceivably do this manually from the command line outside of the IDE) to convert the .ui into a .h and a .cpp file (yourfile.ui becomes ui_yourfile.h).

Related

Set application version on qt?

The application version i setted it is not displayed on the properties of the created .exe file.
I use cmake not .pro file.
QApplication::setApplicationVersion("1.0.0");

CustusX plugin: Where are the compiled .ui files stored and what's the naming convention?

For a plugin for CustusX which realizes GUIExtenderService I want to use a Qt Designer file (.ui) to define the GUI Widget.
The CMakeLists.txt has already a section with:
# Qt Designer files which should be processed by Qts uic
set(PLUGIN_UI_FORMS
)
If I put a ui file there it is processed by the uic tool (if I supply the wrong name it failes on cmake generate). However, I cannot find it again neither in the build directory nor in the source directory.
Where are the compiled ui files placed and what's their name for inclusion?
Seems like I overlooked the obvious - for completeness:
In CmakeLists.txt, add the ui file in the section for the Qt Designer files:
# Qt Designer files which should be processed by Qts uic
set(PLUGIN_UI_FORMS
foo.ui
)
Then a file ui_foo.h is created in the plugin build directory (e.g. my_custus_build_directory/source/plugins/org.custusx.myplugin/ui_foo.h)

Get a .pro file from a Makefile

I have a project that generates a Makefile by using a custom script.
I would like to import this project into Qt Creator but in a way that I can add new files and compile them automatically (without manually editing the Makefile every time).
To simplify, i need a .pro file that would create a currently available Makefile.
Is there a smarter way to do it but to manually check the dependencies for each source file and add them to the .pro file?
qmake -project
should create the project file. Then use the "Add new file..." from Qt Creator to maintain the .pro file automatically.

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

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
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
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.
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
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.
Additionally to the already correct answers: change from Debug to Release mode in the general settings. In my case, the header file wasn't created in Debug mode

How to convert .ui(user interface) files into .exe file in QT

I am a fresher in qt,i don't have much knowledge on qt, but i created some of file in qt for my application (regaurding to GUI format).I was created some .ui files in qt,but i wanted these files into .exe format.I think u had unerstand my problem,so please help me
uic (sometimes installed as uic-4) takes the .ui files and generates a C++ header file that you can inherit from. There are a few different ways you can work with the .ui files. See the manual for more information. Feel free to come back with specific questions.
Hallo Ram,
I think you are asking about the inclusion of .ui files within your .exe file.
If I am not wrong, then you need to include you .ui file within your projects specific resource file. It will be usually named .qrc in Qt projects.
The contents of .qrc file will look something like this:
<RCC>
<qresource prefix="/ui">
<file>ui/command/spiwidget.ui</file>
<file>ui/command/SPIMicroCommandWidget.ui</file>
<file>ui/command/utility/externdatawidget.ui</file>
<file>ui/sequencerwidget.ui</file>
<file>ui/command/watchdogwidget.ui</file>
<file>ui/command/utility/repdatawidget.ui</file>
<file>ui/command/core.png</file>
<file>ui/command/LastOpenedFiles.ui</file>
</qresource>
</RCC>
In the code above, you can see the inclusions for .ui and .png(image file) too.
After including it in .qrc file, you can use this resource in your .cpp code as follows:
QFile file(":ui/ui/command/LastOpenedFiles.ui");
Where :ui/ui/command is the path of to the .ui file being used.
Hope this explanation is useful to you!
Try using QtCreator (official IDE for Qt development). One way to use your *.ui file would bet to:
create *.h and *.cpp files containing a class that will load your widget structure.
add your new files to qt project file - *.pro
If your haven't used Qt Creator yet, then I suggest try it.
Create new project (ctrl+n) - Qt C++ Project / Qt Gui Application
Add new form to your project (ctrl+n) - Qt / Qt Designer Form Class
Look at files that where created by IDE. There is *.h file, *.cpp file and *.ui file.
Look into *.pro file, there are 3 sections SOURCES, HEADERS, FORMS
Here are some learning materials:
http://qt.nokia.com/services-partners/qt-in-education/qt-in-education-course-material

Resources