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
Related
I had to mark some of the .xml files for internationalization. I do not use lupdate manually from cmd, instead I put it in the project's .pro file like:
lupdate_only{
SOURCES += $$EXTRA_XML
}
The above code works just fine, but as you noticed I had to put the xml files in SOURCES. As a consequence the .xml files appear in the Sources virtual folder from the left Projects' perspective window, just next to the .cpp files. I find this solution a bit nasty and confusing.
- Project
- - Headers
- - Sources
- - - main.cpp
- - - some.xml //not wanted here
Is there a way to use lupdate, in .pro, on different files such that those files won't appear in the Sources folder? Thanks!
UPDATE
I use Qt Creator 4.0.3
lupdate_only {
SOURCES += $$EXTRA_XML
}
With this conditional statement, lupdate tool sees the .qml files but qmake will ignore it.
I found the solution to my problem, however I think it's a Qt Creator bug. I just moved the lupdate statement with its contents into a .pri file and now the xml files do not appear under the Sources virtual folder. (the .pri file is included in .pro)
I have built a static Qt library and want to use it deploy my app with a standalone exe. After one day effort, I have known that the qtquick plugin can not be static include into exe.
I need copy some folders in qml folder to my exe directory to let the exe can show GUI.
So I want to know which file my exe need, I deleted files in those folders one by one to get it known. The real needed file is just a plugins.QMLTYPES file and a qmldir file.
And then I found the import path of QQmlApplicationEngine can be changed, I output the QQmlApplicationEngine.importPathList() and one of paths is just the qml folder in Qt installed path. So I think this is the place where Qt get the search path of plugins.QMLTYPES file and qmldir file.
If all I think is correct, I can just copy the folders I need into qrc file and use QQmlApplicationEngine.addImportPath("qrc:/foldersIwant") to let exe can import what it need on runtime. And because qrc is compiled into exe, I can get rid of those folders and let my exe standalone.
But after I do this in my code, app still can not find the files it need even the output of QQmlApplicationEngine.importPathList() has the path I put into and I have also checked my path according to Load qmldir from QRC file.
Here is the code:
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.addImportPath(QStringLiteral("qrc:/import/qtquick/"));
qDebug()<<engine.importPathList();
engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml")));
return app.exec();
}
Here is a part of my qrc file
Is there anything wrong in my deductive?
Further research:
I have add
engine.addImportPath(QDir::currentPath() + QDir::separator() + "custom");
and move all folders into custom folders, it can run successfully. And the exe which doesn't have this line can not run with custom folder. So I'm wondering the "search" behavior can not be applied to qrc file ?
Finally, I get the answer. The result shows all my thoughts are correct!
Below is what I had tried and you can just read the end to get the clear steps.
My aim is to compile a standalone qml2 application exe.
In qml1, I can build static Qt library and compile my app with it.
In qml2, the exe can be compiled in same way. But if I run it without Qt-Runtime. It just do not have any window shown on Windows OS (and also show nothing in other OS). I have googled so many informations and found this problem troubled many people since Qt5.0. Now it is Qt5.5, they still haven't repaired it. So I need copy folders in QT_INSTALLED_PREFIX/qml to the root directory of my app to let my app show GUI.
Althrough the problem will be solved in Qt5.6 (https://codereview.qt-project.org/#/c/114835/), I can't wait for so long (Qt5.6 will be released at the end of this year). So I decide to package the files by myself.
And I see this question by chance :Load qmldir from QRC file. It told me that qmldir file can be include into qrc file and the Qml engine can search into those directory. So I think, the QML files can also be included into qrc file.
But the first thing is to find where the qml2 be imported, when I looking into QQmlApplicationEngine's document, I found addImportPath function and I told myself that it must be the key of finding the import path. The document tells me everything:
QStringList QQmlEngine::importPathList()
const Returns the list of
directories where the engine searches for installed modules in a
URL-based directory structure.
For example, if /opt/MyApp/lib/imports is in the path, then QML that
imports com.mycompany.Feature will cause the QQmlEngine to look in
/opt/MyApp/lib/imports/com/mycompany/Feature/ for the components
provided by that module. A qmldir file is required for defining the
type version mapping and possibly QML extensions plugins.
By default, the list contains the directory of the application
executable, paths specified in the QML2_IMPORT_PATH environment
variable, and the builtin Qml2ImportsPath from QLibraryInfo.
After I delete the Qml2ImportsPath in importPathList at runtime, I made a recurrence of the bugs that app do not show any GUI.
And the document of addImportPath tells my that it can accept qrc url. So I add all the files in qml just like the question described above. But I still cannot see any GUI.
After several days of thinking. I found the pic I posted in question do not have qmldir files! That's a bug of Qt Creator. I add files using Add Existing Directory... and set the filter to *, it still cannot include qmldir file. So I add it into qrc file by xml code.
When I think this time it must work, it just gave me nothing. Just when I was going to give up, a thought occurred : it won't waste me more time to check whether qrc:/import/qtquick/ is valid.
The result is false, there must be a mistake in my qrc usage. I change the prefix and save the qrc with Qt Creator. I found the qrc file cannot use the path like D:/Qt/Qt-5.5-static/qml/Qt/labs/folderlistmodel/plugins.qmltypes, it is changed by Qt Creator to Qt/labs/folderlistmodel/plugins.qmltypes. At this time, everything works perfect!
Thanks for you reading my story. Here is a conclusion of steps for solving this problem:
Copy all folders in QT_INSTALLED_PREFIX/qml to your project folder, it is good to put them under a parent folder not the root folder.
Write some code to get all files' relative path except the .lib files and
.prl files.
Create a new .qrc file and include it in .pro file. Include all files into this .qrc file. I wrote a small program to generate the xml.
Add the import path using addImportPath method of QQmlApplicationEngine.
Build and enjoy.
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)
Assume the following directory structure
project/project.pro
project/project.pri
In this case even if the project.pro file does not have a statement like (include project.pri). Does it gets included automatically by qmake.
In the qtcreator sources plugin directory
qt-creator/src/plugins/coreplugin
There is a coreplugin.pri file which is not included in the coreplugin.pro file
I'm fairly confident that it does not get included automatically, and I did a quick test with a .pro and a .pri file that had message calls in them to confirm this.
With regards to the files you're seeing in creator, it's not uncommon to have a .pri file that is designed for other .pro files to include so that you can use the project.
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