User forums > Using Code::Blocks
Preprocessing Qt files without the Qtworkbench plugin?
rickg22:
Hi guys! I'm switching my project from wxWidgets (bye bye!) to Qt, and I have stumbled upon the dreaded "moc" issue (signals and slots don't work without moc).
I was wondering if there could be a way (scripting, who knows) to pass files through moc so that I don't have to use Qmake in the first place? I've come to like direct compiling :)
Now, my approach is this: If I have a c++ file (myfile.cpp or myfile.h), I pass that file through moc manually and redirect the output to myfile.moc.h, and include myfile.moc.h inside myfile.cpp.
I wanted to know if I could automate this process somehow using targets/dependencies/whatever, whenever either the c++ or h file is changed.
dgoemans:
Hey, i was faced with the same problem recently and wrote a build script for it ( did a write up here: http://bushweed.blogspot.com/2008/10/pragma-once.html ) , but i was wondering if this would be possible to incorporate this into the IDE? If anyone could give me the best place to build this in, i was thinking of just adding the build script to the Qt project template, however, the biggest problem is that it generates these new cpp's which aren't auto added to the project. Any suggestions?
amarty:
I use custom build for moc'ing Qt headers.
* Go to project build options - Debug, "Custom variables" tab. Add target=Debug
Switch to Release configuration, add target=Release. Perform this step for all existing configurations.
* Open Properties dialog for header that requires moc'ing (Add this file to project, it appears in "Headers" virtual folder). Go to "Build" tab, check "Compile file", uncheck "Link file".
* Go to "Advanced tab". Check "Use custom command to build this file"
--- Code: ---cmd /C if not exist $file_dir\generatedFiles\$(TARGET_NAME) mkdir $file_dir\generatedFiles\$(TARGET_NAME)
moc $includes $file -o $file_dir\generatedFiles\$(TARGET_NAME)\moc_$file_name.cpp
--- End code ---
(Command above is for Windows, for Linux use md for creating directory)
[/li]
* Press Ok and close dialog
* Right click on file and select "Build file"
* Right click on project and select "Add files...". Choose $(YOUR_SRC_PATH)\generatedFiles\$(TARGET_NAME)\moc_$(YOUR_FILE).cpp ( $(TARGET_NAME) - is name of currently selected configuration)
* Right click on moc_$(YOUR_FILE).cpp in project tree, select properties. Open "Build" tab, unckeck all targets, keep checked only currently selected. Close dialog.
* Select next project configuration, build moc_*.cpp, add it, and attach it to build with current configuration. Make this steps for all your configurations.
This is the way to tune up C::B build system to work like MSVC with Qt integrator.
amarty:
--- Quote from: amarty on January 22, 2009, 03:48:36 pm ---I use custom build for moc'ing Qt headers.
* Go to project build options - Debug, "Custom variables" tab. Add target_name1=Debug
--- Quote ---cmd /C if not exist $file_dir\generatedFiles\$(TARGET_NAME2) mkdir $file_dir\generatedFiles\$(TARGET_NAME3)
moc $includes $file -o $file_dir\generatedFiles\$(TARGET_NAME4)\moc_$file_name.cpp
--- End quote ---
--- End quote ---
Add _name in step (1) or remove (2), (3) and (4).
rickg22:
What I'm doing right now is processing the .moc files by hand and including them from the .cpp files. The same goes for the .qrc files (i precompile them with rcc and upload the .rcc files to the SVN repository).
Altho it's a bit tedious whenever you do any changes to UI-specific code, you can be sure that anyone will be able to compile the result without having to rely on Qt-specific tools.
Navigation
[0] Message Index
[#] Next page
Go to full version