Author Topic: Preprocessing Qt files without the Qtworkbench plugin?  (Read 5393 times)

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Preprocessing Qt files without the Qtworkbench plugin?
« on: January 09, 2009, 08:08:01 pm »
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

  • Guest
Re: Preprocessing Qt files without the Qtworkbench plugin?
« Reply #1 on: January 21, 2009, 09:55:35 pm »
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?

Offline amarty

  • Multiple posting newcomer
  • *
  • Posts: 41
Re: Preprocessing Qt files without the Qtworkbench plugin?
« Reply #2 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=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
    (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.

Offline amarty

  • Multiple posting newcomer
  • *
  • Posts: 41
Re: Preprocessing Qt files without the Qtworkbench plugin?
« Reply #3 on: January 22, 2009, 03:52:54 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

 Add _name in step (1) or remove (2), (3) and (4).

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Re: Preprocessing Qt files without the Qtworkbench plugin?
« Reply #4 on: February 22, 2009, 06:22:05 pm »
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.

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: Preprocessing Qt files without the Qtworkbench plugin?
« Reply #5 on: February 22, 2009, 07:05:37 pm »
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.

Offline rickg22

  • Lives here!
  • ****
  • Posts: 2283
Re: Preprocessing Qt files without the Qtworkbench plugin?
« Reply #6 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.

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: Preprocessing Qt files without the Qtworkbench plugin?
« Reply #7 on: February 25, 2009, 03:46:33 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.