QT4: how to generate header files from ui
-
wrote on 10 Jun 2021, 14:28 last edited by
I'm working on a legacy project written in cpp under Visual Studio 2010. This is a desktop application built with QT4.
I'm an absolute beginner in the QT world, so maybe the question I'm going to ask is really trivial but I didn't find a simple solution to my problem. As you can see from the screenshoot below (taken from the visual studio project), there are 15 "header" and "cpp" files which have the same name as the "ui" files, so I guess there is a way to automatically generate them. Do you know how to generate them? Because they are missing from the solution.
Thanks for reading
-
wrote on 10 Jun 2021, 14:56 last edited by JoeCFD 6 Oct 2021, 14:59
.ui files are generated with qt designer. ui_ and moc_ files are created whenever ui and widget files are compiled. If you make clean, ui_ and moc_ files will be cleared.
Try to double click any .ui file, qt designed may pop-up -
I'm working on a legacy project written in cpp under Visual Studio 2010. This is a desktop application built with QT4.
I'm an absolute beginner in the QT world, so maybe the question I'm going to ask is really trivial but I didn't find a simple solution to my problem. As you can see from the screenshoot below (taken from the visual studio project), there are 15 "header" and "cpp" files which have the same name as the "ui" files, so I guess there is a way to automatically generate them. Do you know how to generate them? Because they are missing from the solution.
Thanks for reading
Lifetime Qt Championwrote on 11 Jun 2021, 06:52 last edited by jsulm 6 Nov 2021, 06:54@brianenno said in QT4: how to generate header files from ui:
Do you know how to generate them? Because they are missing from the solution.
These files are auto-generated and should NOT be added directly to the project (and not added to code version systems)! And you also should not edit this generated files manually as you will loose your changes next time these files are generated.
Take a look at https://doc.qt.io/qt-5/designer-using-a-ui-file.html and https://doc.qt.io/qt-5/moc.html for more information -
wrote on 12 Jun 2021, 17:07 last edited by
Hi, thanks @JoeCFD and @jsulm for your replies.
But I'm still struggling with the solution build. I think I have successfully installed QT4 and QTCreator because if I "double click" on the .ui file, the QT Designer is popped up properly and I can see the form.But I really didn't understand what is the purpose of the "uic" command. If I try to execute the command, I get a cpp class content.
@jsulm in visual studio I tried to get rid of those files and tried to re-compile the code from scratch and I get the following error:
CustomBuild: Moc'ing qextserialbase.h... The system cannot find the path specified. Moc'ing qextserialenumerator.h... The system cannot find the path specified. Moc'ing qextserialport.h... The system cannot find the path specified. Moc'ing win_qextserialport.h... The system cannot find the path specified. C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets(151,5): error MSB6006: "cmd.exe" exited with code 3.
That's really strange because (for example) the file "qextserialenumerator.h" is present in the directory.
What is the purpose of "moc-ing"? Why it is trying to "moc" my qt files?
Thanks for reading
Brianenno -
Lifetime Qt Championwrote on 12 Jun 2021, 19:51 last edited by mrjj 6 Dec 2021, 19:51
Hi
The UIC converts the UI files to c++ code.
https://doc.qt.io/qt-5/uic.html
so it parses the UI file and generates code that will create that layout.Moc'ing
https://doc.qt.io/qt-5/why-moc.html
https://doc.qt.io/qt-5/moc.html
1/5