Using *.ui files with c++

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
Oli
Posts: 7
Joined: Wed Oct 05, 2016 3:04 pm

Using *.ui files with c++

Post by Oli »

Hello everyone,
I'm new to development with FreeCAD and Qt. I want to add some new functionality to FreeCAD. I have an old programm (written in c++) and want to use it with FreeCAD. Therefore I created a new workspace. Now I try to create some new dialogs for data input that I need.
I develop with Visual Studio and installed Qt and Qt plugin vor VS. If I create a new dialog with Qt Designer I don' get it, how to use this *.ui file within FreeCAD. I think i need a *.h file (how can I automatically create this with Qt?) I found only documentation for python, hence the old code is in c++ and I'm better with c++ I want to do this in c++. Can you tell me how to do this, or do you have a good tutorial for me?
User avatar
wandererfan
Veteran
Posts: 6326
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Using *.ui files with c++

Post by wandererfan »

The magic happens in myModule/Gui/CMakeLists.txt. These two lines:

Code: Select all

fc_wrap_cpp(TechDrawGui_MOC_SRCS ${TechDrawGui_MOC_HDRS})
qt4_wrap_ui(TechDrawGui_UIC_HDRS ${TechDrawGui_UIC_SRCS})

generate .cpp and .h files from your .ui.
you then include them in your dialog code.

Code: Select all

#include <Mod/TechDraw/Gui/ui_TaskLinkDim.h>
...
#include <Mod/TechDraw/Gui/moc_TaskLinkDim.cpp>
The generated files hide all the messy bits of building the ui in your code.
Oli
Posts: 7
Joined: Wed Oct 05, 2016 3:04 pm

Re: Using *.ui files with c++

Post by Oli »

Thanks for the answer!
i have added my *.ui files in the CMakeLists.txt. But where do I find the generated *.h and *.cpp files? They are neither in the folder /src/Mod/MyModule/Gui, nor in Mod/MyModule.
User avatar
wandererfan
Veteran
Posts: 6326
Joined: Tue Nov 06, 2012 5:42 pm
Contact:

Re: Using *.ui files with c++

Post by wandererfan »

Oli wrote:Thanks for the answer!
i have added my *.ui files in the CMakeLists.txt. But where do I find the generated *.h and *.cpp files? They are neither in the folder /src/Mod/MyModule/Gui, nor in Mod/MyModule.
I had trouble finding them too! They're in the build directory: BuildDir/src/Mod/MyModule/Gui...

Your includes will have to include path info:

Code: Select all

#include <Mod/TechDraw/Gui/ui_TaskLinkDim.h>
...
#include <Mod/TechDraw/Gui/moc_TaskLinkDim.cpp>
If you just use #include "ui_TaskLinkDim.h" the file won't be found.
Post Reply