Results 1 to 7 of 7

Thread: MOC'ing with #include's

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2006
    Posts
    22
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default MOC'ing with #include's

    [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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: MOC'ing with #include's

    Do you have semicolons at the end of each #include statement?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Feb 2006
    Posts
    22
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: MOC'ing with #include's

    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.)

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: MOC'ing with #include's

    Can we get an example of an exact error together with the offending line and its surroundings?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Feb 2006
    Posts
    22
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: MOC'ing with #include's

    A (reduced) .H with 2 (reduced) include files as example:

    Secretary.h
    Qt Code:
    1. class Secretary : public QMainWindow
    2. {
    3. Q_OBJECT
    4.  
    5.  
    6. public:
    7.  
    8. // constructor
    9. Secretary( QWidget * parent = 0,
    10. Qt::WFlags flags = 0 );
    11. // destructor
    12. ~Secretary();
    13.  
    14.  
    15. private:
    16.  
    17. // user interface
    18. Ui::SecretaryClass ui;
    19.  
    20.  
    21. #include "SecretaryH_tabMain_ClassScope.h"
    22. #include "SecretaryH_tabMainHuman_ClassScope.h"
    23. };
    To copy to clipboard, switch view to plain text mode 

    SecretaryH_tabMain_ClassScope.h
    Qt Code:
    1. private:
    2.  
    3. // init tab
    4. int Secretary::iTabMain_InitTab( int a_iTabIndex );
    5. // tab index changed
    6. int Secretary::iTabMain_TabIndexChanged( int a_iNewTabIndex );
    7.  
    8.  
    9. private slots:
    10.  
    11. void on_tabMain_currentChanged( int a_iIndex );
    To copy to clipboard, switch view to plain text mode 

    SecretaryH_tabMainHuman_ClassScope.h
    Qt Code:
    1. private:
    2.  
    3. // list model
    4. Model_TableView1 * ptTabMainHumanList_Model;
    5.  
    6. // setup list model
    7. int iTabMainHumanList_SetupModel( void );
    8. // teardown list model
    9. int iTabMainHumanList_TeardownModel( void );
    10.  
    11. // clear and load list header data
    12. int iTabMainHumanList_ClearLoadHeaderData( void );
    13.  
    14. // clear list data
    15. int iTabMainHumanList_ClearData( void );
    16. // clear and load list data
    17. int iTabMainHumanList_ClearLoadData( void );
    18.  
    19.  
    20. private slots:
    21.  
    22. void on_tableHumanList_clicked( const QModelIndex & item );
    23.  
    24. void on_buttonHumanCreateNew_clicked();
    25. void on_buttonHumanCopyNew_clicked();
    26. void on_buttonHumanEdit_clicked();
    27. void on_buttonHumanDelete_clicked();
    To copy to clipboard, switch view to plain text mode 

    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 ==========

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: MOC'ing with #include's

    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?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Feb 2006
    Posts
    22
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: MOC'ing with #include's

    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

Similar Threads

  1. X11 include and lib paths
    By Oluwafemi in forum Installation and Deployment
    Replies: 1
    Last Post: 3rd April 2010, 15:25
  2. How to include a dll ???
    By anupamgee in forum Qt Programming
    Replies: 1
    Last Post: 29th March 2010, 08:28
  3. mfc in QT include
    By trusch in forum Qt Programming
    Replies: 3
    Last Post: 16th July 2009, 10:01
  4. include
    By mickey in forum Newbie
    Replies: 6
    Last Post: 4th April 2006, 23:14

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.