Results 1 to 8 of 8

Thread: Failed to compiled QT4 with Q_OBJECT when include header file

  1. #1
    Join Date
    Aug 2015
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Failed to compiled QT4 with Q_OBJECT when include header file

    Hi, I have spend 1 week try to resolve the problem but still failed. Would like to seek you guy help on below error.

    I had build a simple form with feature for signal/slots. So Q_OBJECT is a must. In my header file myQtApp.h, I try to include header file "scsicmd.h" & "atacmd.h" (link to static library) it failed to compiled. Below is error message and code and project file. Hope somebody can guide me. Thanks you very much.

    root@udoobuntu: /home/ubuntu/firstGUI $ qmake
    root@udoobuntu: /home/ubuntu/firstGUI $ make
    g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_WEBKIT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mk
    specs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -o myqtapp.o myqtapp.cpp
    In file included from myqtapp.cpp:7:0:
    myqtapp.h:20:5: error: expected nested-name-specifier before numeric constant
    myqtapp.h:20:5: error: expected '>' before numeric constant
    myqtapp.h:20:5: error: ISO C++ forbids declaration of 'parameter' with no type [-fpermissive]
    myqtapp.h:20:5: error: expected ',' or '...' before numeric constant
    myqtapp.h: In member function 'void myQtApp::qt_check_for_QOBJECT_macro(int) const':
    myqtapp.h:20:5: error: '_q_argument' was not declared in this scope
    myqtapp.cpp: At global scope:
    myqtapp.cpp:11:1: warning: unused parameter 'parent' [-Wunused-parameter]
    make: *** [myqtapp.o] Error 1
    root@udoobuntu: /home/ubuntu/firstGUI $



    myqtapp.h code:
    Qt Code:
    1. #ifndef MYQTAPP_H
    2. #define MYQTAPP_H
    3.  
    4. #include "scsicmd.h" //SCSI Command Library (static) <--- error failed to compiled
    5. #include "atacmd.h" //ATA Command Library (static) <--- error failed to compiled
    6. #include "ui_myqtapp.h"
    7.  
    8. #include <unistd.h>
    9. #include <fcntl.h>
    10. #include <stdio.h>
    11. #include <string.h>
    12. #include <errno.h>
    13. #include <fstream>
    14. #include <sys/ioctl.h>
    15. #include <sys/types.h>
    16. #include <scsi/sg.h>
    17.  
    18. class myQtApp : public QWidget, private Ui::myQtAppDLG
    19. {
    20. Q_OBJECT //<--- all error point to this line 20 !!!
    21.  
    22. public:
    23. myQtApp(QWidget *parent = 0);
    24. ~myQtApp();
    25. sg_io_hdr_t io_hdr; //SCSI Generic Structure
    26. SCSICmd *SCSICommand;
    27. ATACmd *ATACommand;
    28. int sg_dev;
    29.  
    30.  
    31. public slots:
    32. void getPath();
    33. void doSomething();
    34. void clear();
    35. void about();
    36.  
    37. void bufferdump(char *d,unsigned int);
    38. void ByteSwapAll(unsigned char *buffer, int size);
    39. DWORD dwordReverse (DWORD dword);
    40. WORD wordReverse (WORD word);
    41. void openlib();
    42. void openDevice(int dev=0);
    43.  
    44.  
    45. protected:
    46. u_char dataBuffer[512*512];
    47. u_char senseBuffer[64];
    48. u_char errorBuffer[64];
    49. DWORD tx_len;
    50. char tmp[10];
    51. char model[22];
    52. char vendor[8];
    53. char fw[8];
    54. char serial[20];
    55. BYTE byReadCap [8];
    56. UINT blocksize;
    57. UINT dwMaxLBA;
    58. UINT capacity;
    59. };
    60.  
    61.  
    62. #endif
    To copy to clipboard, switch view to plain text mode 

    myqtapp.pro file:
    Qt Code:
    1. HEADERS = atacmd.h scsicmd.h myqtapp.h
    2. SOURCES = myqtapp.cpp main.cpp
    3. FORMS = myqtapp.ui
    4. LIBS = /usr/local/lib/libATACmd.a /usr/local/lib/libSCSICmd.a
    5.  
    6. # install
    7. target.path = myqtapp
    8. sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS *.pro
    9. sources.path = .
    10. INSTALLS += target sources
    To copy to clipboard, switch view to plain text mode 
    Last edited by teleplan; 26th August 2015 at 09:04.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,229
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Failed to compiled QT4 with Q_OBJECT when include header file

    Your class is derived from QWidget. Where is your #include <QWidget> (which will at some point include the header where Q_OBJECT is defined)?

  3. #3
    Join Date
    Aug 2015
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Failed to compiled QT4 with Q_OBJECT when include header file

    Hi, Thanks for your reply. This program originally is working good without any problem. I already included QTGui in myqtapp.cpp file.
    The problem occur once I add in the static library with 2 include header file [scsicmd.h] & [atacmd.h] then it failed to compiled and all error point to Q_OBJECT line.

    In myqtapp.cpp which I not posted here, I already include
    #include <QtGui>
    #include "myqtapp.h"

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Failed to compiled QT4 with Q_OBJECT when include header file

    What if you just separate UI and processing into to classes?
    A sensible thing to do in any case and could totally avoid the problem you are seeing.

    Cheers,
    _

  5. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,229
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Failed to compiled QT4 with Q_OBJECT when include header file

    Possibly the problem is the private inheritance of Ui::myQtAppDLG. Try changing it to public or protected. The Q_OBJECT macro inserts some Qt meta-object source code into the class definition, and maybe this is incompatible with private inheritance of the UI class.

    And take anda_skoa's suggestion for separating UI and processing code into different classes. It is never a good design to mix the two up. Makes for bad spaghetti.

  6. #6
    Join Date
    Aug 2015
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Failed to compiled QT4 with Q_OBJECT when include header file

    Quote Originally Posted by anda_skoa View Post
    What if you just separate UI and processing into to classes?
    A sensible thing to do in any case and could totally avoid the problem you are seeing.

    Cheers,
    _

    Hi anda_skoa & d_stranz

    I new with QT GUI, I using QT designer to generate a form. Then I use normal editor to write a source file. Original I use a sample code from internet which is running well. Once I add in my code [Not touch on any QT code] then it compiled error.

    I not sure how to separate the UI, can you provide me guideline/example based on my above sample code? I had stuck with this many weeks.. really hope can settle it soon. bcoz backend I still need to do lots low level hardisk drive code.

    I just need a simple GUI with few button, the button will send some hard disk command to retrieve some information. :-)

    Thanks again.

    Quote Originally Posted by d_stranz View Post
    Possibly the problem is the private inheritance of Ui::myQtAppDLG. Try changing it to public or protected. The Q_OBJECT macro inserts some Qt meta-object source code into the class definition, and maybe this is incompatible with private inheritance of the UI class.

    And take anda_skoa's suggestion for separating UI and processing code into different classes. It is never a good design to mix the two up. Makes for bad spaghetti.
    I had try this, unfortunately still same error.

  7. #7
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Failed to compiled QT4 with Q_OBJECT when include header file

    Quote Originally Posted by teleplan View Post
    I not sure how to separate the UI, can you provide me guideline/example based on my above sample code?
    You put all the non-UI code into a separate class and let the widget hold an instance of that class as a pointer.
    That way you do not need any of these other includes in the header that has the Q_OBJECT.

    Cheers,
    _

  8. #8
    Join Date
    Aug 2015
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Failed to compiled QT4 with Q_OBJECT when include header file

    Quote Originally Posted by anda_skoa View Post
    You put all the non-UI code into a separate class and let the widget hold an instance of that class as a pointer.
    That way you do not need any of these other includes in the header that has the Q_OBJECT.

    Cheers,
    _
    Hi anda_skoa,

    Yes, it compiled now, I separate the non-UI code into another class.
    Really not understand, why my previous QT3 can compiled without any problem which include non-UI code.

    Anyway thanks for help...

Similar Threads

  1. How to force include a header file
    By rawfool in forum Newbie
    Replies: 25
    Last Post: 14th December 2015, 00:34
  2. Replies: 0
    Last Post: 25th July 2011, 15:47
  3. The header file 'mainwindow.h' doesn't include <QObject>.
    By nhs_0702 in forum Qt Programming
    Replies: 5
    Last Post: 14th May 2010, 18:02
  4. Failed to Launch qt 4.4.0 compiled executable in Debug mode
    By nikhilqt in forum Installation and Deployment
    Replies: 2
    Last Post: 25th July 2008, 14:45
  5. unable to include header file
    By sonia in forum Qt Programming
    Replies: 1
    Last Post: 10th July 2007, 09:56

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.