News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

Preprocessing Qt files without the Qtworkbench plugin?

Started by rickg22, January 09, 2009, 08:08:01 PM

Previous topic - Next topic

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"
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
    (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
Quotecmd /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

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.

dmoore

can't the "advanced compiler options" handle this case? create a new compiler derived from gcc then add extra command handlers for the relevant file types.
Python plugins: [url="https://github.com/spillz/codeblocks-python"]https://github.com/spillz/codeblocks-python[/url]
Code::Blocks Daily Builds -- Ubuntu PPA: [url="https://launchpad.net/~damien-moore/+archive/codeblocks"]https://launchpad.net/~damien-moore/+archive/codeblocks[/url]

rickg22

Well, the problem is that (at least to my knowledge, please correct me if I'm wrong), the advanced compiler options are NOT project-specific. Hence, the code's not portable across different users.

dmoore

Quote from: rickg22 on February 25, 2009, 03:19:39 PM
Well, the problem is that (at least to my knowledge, please correct me if I'm wrong), the advanced compiler options are NOT project-specific. Hence, the code's not portable across different users.


the compiler chosen for each target is stored persistently in the project file. you just need a mechanism to export and deploy compilers.
Python plugins: [url="https://github.com/spillz/codeblocks-python"]https://github.com/spillz/codeblocks-python[/url]
Code::Blocks Daily Builds -- Ubuntu PPA: [url="https://launchpad.net/~damien-moore/+archive/codeblocks"]https://launchpad.net/~damien-moore/+archive/codeblocks[/url]