PDA

View Full Version : MOC'ing with #include's



mule
7th January 2012, 21:15
[Using Qt 4.7.4 and Qt Add-In 1.1.9 with Visual Studio 2008]

I have a .H defining a class that is a Q_OBJECT.
The class contains many "parts".
To keep the source file size manageable, the "parts" are separated into separate files.
Within the class definition, #include preprocessor directives are used to pull the separate files into the .H for compilation.
However, while MOC'ing (I believe) the following error is generated:
<file>.h(<line>): Parse error at ";"

Commenting out the #include's and copy&pasting the files directly into the .H works file.

Any suggestions on getting around this "limitation"?
Thanks.

wysota
7th January 2012, 21:30
Do you have semicolons at the end of each #include statement?

mule
7th January 2012, 21:47
No. There are no ";" after the #includes in the original .H file.
Also, there are no extra ";"s in the included files. (They can be copy&pasted in without error.)

wysota
7th January 2012, 22:01
Can we get an example of an exact error together with the offending line and its surroundings?

mule
7th January 2012, 22:32
A (reduced) .H with 2 (reduced) include files as example:

Secretary.h

class Secretary : public QMainWindow
{
Q_OBJECT


public:

// constructor
Secretary( QWidget * parent = 0,
Qt::WFlags flags = 0 );
// destructor
~Secretary();


private:

// user interface
Ui::SecretaryClass ui;


#include "SecretaryH_tabMain_ClassScope.h"
#include "SecretaryH_tabMainHuman_ClassScope.h"
};

SecretaryH_tabMain_ClassScope.h

private:

// init tab
int Secretary::iTabMain_InitTab( int a_iTabIndex );
// tab index changed
int Secretary::iTabMain_TabIndexChanged( int a_iNewTabIndex );


private slots:

void on_tabMain_currentChanged( int a_iIndex );

SecretaryH_tabMainHuman_ClassScope.h

private:

// list model
Model_TableView1 * ptTabMainHumanList_Model;

// setup list model
int iTabMainHumanList_SetupModel( void );
// teardown list model
int iTabMainHumanList_TeardownModel( void );

// clear and load list header data
int iTabMainHumanList_ClearLoadHeaderData( void );

// clear list data
int iTabMainHumanList_ClearData( void );
// clear and load list data
int iTabMainHumanList_ClearLoadData( void );


private slots:

void on_tableHumanList_clicked( const QModelIndex & item );

void on_buttonHumanCreateNew_clicked();
void on_buttonHumanCopyNew_clicked();
void on_buttonHumanEdit_clicked();
void on_buttonHumanDelete_clicked();


Build output is:

1>------ Build started: Project: Secretary, Configuration: Release Win32 ------
1>Moc'ing Secretary.h...
1>.\Secretary.h(75): Parse error at ";"
1>Project : error PRJ0019: A tool returned an error code from "Moc'ing Secretary.h..."
1>Build log was saved at "file://\\psf\Home\Desktop\GAB\v1.0.0\Secretary\Release\Bu ildLog.htm"
1>Secretary - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

wysota
7th January 2012, 22:40
I think MOC doesn't expect to get an include statement inside a class definition. It can't process such include since it doesn't know how to include files itself. Shouldn't you be using subclassing (or templates) instead of including?

mule
7th January 2012, 22:48
Yes, you are correct. I should use subclassing.
This thing started as one huge source file, and I was trying to cheat and do it the fast way by just breaking it up and including the pieces, without modifying the code.

You are most likely also correct that MOC doesn't know what to do with the #includes. I was hoping to be able to run the preprocessor before MOCing to do the includes, but I could not figure out how to do that.

I will start editing to do it the correct way.

Thanks, w!

mule