Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: rickg22 on January 09, 2009, 08:08:01 pm

Title: Preprocessing Qt files without the Qtworkbench plugin?
Post by: rickg22 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.
Title: Re: Preprocessing Qt files without the Qtworkbench plugin?
Post by: dgoemans 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?
Title: Re: Preprocessing Qt files without the Qtworkbench plugin?
Post by: amarty on January 22, 2009, 03:48:36 pm
I use custom build for moc'ing Qt headers.
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

This is the way to tune up C::B build system to work like MSVC with Qt integrator.
Title: Re: Preprocessing Qt files without the Qtworkbench plugin?
Post by: amarty 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).
Title: Re: Preprocessing Qt files without the Qtworkbench plugin?
Post by: rickg22 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.
Title: Re: Preprocessing Qt files without the Qtworkbench plugin?
Post by: dmoore 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.
Title: Re: Preprocessing Qt files without the Qtworkbench plugin?
Post by: 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.
Title: Re: Preprocessing Qt files without the Qtworkbench plugin?
Post by: dmoore 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.