Results 1 to 17 of 17

Thread: error using Q_OBJECT

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2008
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default error using Q_OBJECT

    hi,i'm using code::blocks and i have these 3 files:

    main.cpp
    Qt Code:
    1. #include <QApplication>
    2. #include "dlgjanela.h"
    3. //Inclusão da janela de teste
    4.  
    5.  
    6.  
    7.  
    8. int main(int argc, char** argv)
    9. {
    10. QApplication app(argc, argv);
    11. dlgjanela janela;
    12. janela.show();
    13. return app.exec();
    14. }
    To copy to clipboard, switch view to plain text mode 


    dlgjanela.h
    Qt Code:
    1. //código para proteger multipla inclusao de headerss
    2. #ifndef DLGJANELA_H
    3. #define DLGJANELA_H
    4.  
    5.  
    6.  
    7. #include <QDialog>
    8.  
    9. //inicio da declaração prévia das classes
    10.  
    11. class QLabel;
    12. //como a classe não existe iremos fazer uma declaração pe+via para avisar que existe
    13. //pois iria dar um erro de compilação
    14.  
    15.  
    16.  
    17. //protótipo da janela de teste
    18.  
    19. class dlgjanela: public QDialog
    20. {
    21.  
    22.  
    23. Q_OBJECT
    24.  
    25.  
    26. public:
    27. dlgjanela(QWidget* parent=0);
    28.  
    29.  
    30.  
    31.  
    32.  
    33. private slots:
    34. void disable();
    35.  
    36.  
    37.  
    38. private:
    39. //no private normalmente são declarações dos widgets que irão existir no dialogo
    40. //os tipos de variavel devem existir ou estar presente npos headers
    41. QLabel* label;
    42. QPushButton* botao;
    43. QVBoxLayout* layout;
    44.  
    45.  
    46. };
    47. #endif
    48. //fim protecção multiplas inclusões
    To copy to clipboard, switch view to plain text mode 


    dlgjanela.cpp
    Qt Code:
    1. #include <QtGui>//classe que contém uma
    2. #include "dlgjanela.h"
    3.  
    4. //uma vez declarado os prototipos no header,implementamos os metodos das classes
    5. dlgjanela::dlgjanela(QWidget* parent):QDialog(parent)
    6. {
    7.  
    8. label=new QLabel("ola eliseu");
    9. botao=new QPushButton("Sair");
    10.  
    11. //conexões
    12. connect(botao,SIGNAL(clicked()),qApp,SLOT(disable()));
    13.  
    14. layout= new QVBoxLayout;
    15. layout->addWidget(label);
    16. layout->addWidget(botao);
    17. setLayout(layout);
    18.  
    19. }
    20.  
    21.  
    22.  
    23. void dlgjanela::disable()
    24. {
    25. botao->setEnabled(false);
    26. }
    To copy to clipboard, switch view to plain text mode 


    when i try to compile i'm getting this error:


    obj\Debug\main.o||In function `_ZSt17__verify_groupingPKcjRKSs':|
    D:\Programas\CodeBlocks\MinGW\bin\..\lib\gcc\mingw 32\3.4.5\..\..\..\..\include\c++\3.4.5\bits\locale _facets.tcc|2498|undefined reference to `vtable for dlgjanela'|
    D:\Programas\CodeBlocks\MinGW\bin\..\lib\gcc\mingw 32\3.4.5\..\..\..\..\include\c++\3.4.5\bits\locale _facets.tcc|2499|undefined reference to `vtable for dlgjanela'|
    obj\Debug\dlgjanela.o||In function `_ZN9dlgjanelaC2EP7QWidget':|
    D:\Documents and Settings\Juliana Leticia\Ambiente de trabalho\projectos-Qt\estudos\dlgjanela.cpp|6|undefined reference to `vtable for dlgjanela'|
    D:\Documents and Settings\Juliana Leticia\Ambiente de trabalho\projectos-Qt\estudos\dlgjanela.cpp|6|undefined reference to `vtable for dlgjanela'|
    obj\Debug\dlgjanela.o||In function `_ZN9dlgjanelaC1EP7QWidget':|
    D:\Documents and Settings\Juliana Leticia\Ambiente de trabalho\projectos-Qt\estudos\dlgjanela.cpp|6|undefined reference to `vtable for dlgjanela'|
    obj\Debug\dlgjanela.o:D:\Documents and Settings\Juliana Leticia\Ambiente de trabalho\projectos-Qt\estudos\dlgjanela.cpp|6|more undefined references to `vtable for dlgjanela' follow|
    ||=== Build finished: 6 errors, 0 warnings ===|
    could you help me please?
    Last edited by wrproject; 1st July 2008 at 22:32.

  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: error using Q_OBJECT

    You have to run moc on the header file containing the Q_OBJECT macro. Usually qmake handles that, but I guess you are not using it, so you have to do it manually.

  3. #3
    Join Date
    Jun 2008
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: error using Q_OBJECT

    and how i do that? i'm very noob.

  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: error using Q_OBJECT

    Run moc --help and read the help text. I really suggest you use qmake, though.

  5. #5
    Join Date
    Jun 2008
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: error using Q_OBJECT

    i really didn't understand how to do that, i always use code::blocks to compile my programs.
    there isn't any tutorial for noobs please?

  6. #6
    Join Date
    Jun 2008
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: error using Q_OBJECT

    i already did the makefile,and the .pro file, now wich the command to compile the project to be able read the Q_OBJECT macro?

  7. #7
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: error using Q_OBJECT

    Add your header to HEADERS section in pro-File and rerun qmake
    See also qmake Documentation

  8. #8
    Join Date
    Jun 2008
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: error using Q_OBJECT

    i did everything what you say,but no sucess.
    once i'm noob to Qt its very hard to me to understand how to integrate the makefile whith "code::blocks".
    if anyone found a tutorial to integrate the makefiles witg "code::blocks" i,d thanks.
    thank you all ,i will keep trying myself,maybe will result.

  9. #9
    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: error using Q_OBJECT

    What part of "moc --help" did you not understand?

  10. #10
    Join Date
    Jun 2008
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: error using Q_OBJECT

    Please, i used "moc --help" and it show me severals options,i dont know what to do with all these options.
    i think it's better addme in msn to me explain better my problem and solve it.
    once again, thank you.

  11. #11
    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: error using Q_OBJECT

    I said "run moc on your header file" so you should have at least tried writing "moc myheaderfile.h". Or please use qmake. If you don't know how, please open Assistant, browse to qmake manual and read at least the first section of it.

  12. #12
    Join Date
    Jun 2008
    Posts
    9
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: error using Q_OBJECT

    i think i will use another IDE,more peoples have the same problems using code::blocks.
    which IDE you use to compile your Qt programas?

  13. #13
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: error using Q_OBJECT

    Quote Originally Posted by wrproject View Post
    i think i will use another IDE,more peoples have the same problems using code::blocks.
    which IDE you use to compile your Qt programas?
    Visual Studio Express is a good choice on Windows. Since Qt 4.3.2, qmake is able to generate fully working Visual Studio project files by invoking "qmake -tp vc".
    J-P Nurmi

  14. #14
    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: error using Q_OBJECT

    There is always Eclipse, if one likes java-based apps...

  15. #15
    Join Date
    Apr 2007
    Posts
    23
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: error using Q_OBJECT

    I am pretty sure you need a semi-colon after the Q_OBJECT key word;

    Qt Code:
    1. class yada: public nada
    2. {
    3. Q_OBJECT;
    4.  
    5. ...
    6.  
    7. }
    To copy to clipboard, switch view to plain text mode 

  16. #16
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: error using Q_OBJECT

    Quote Originally Posted by markcole View Post
    I am pretty sure you need a semi-colon after the Q_OBJECT key word
    No, it isn't necessary.

  17. #17
    Join Date
    Apr 2007
    Posts
    23
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: error using Q_OBJECT

    Quote Originally Posted by jacek View Post
    No, it isn't necessary.
    Good to know...

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.