PDA

View Full Version : error using Q_OBJECT



wrproject
1st July 2008, 22:23
hi,i'm using code::blocks and i have these 3 files:

main.cpp



#include <QApplication>
#include "dlgjanela.h"
//Inclusão da janela de teste




int main(int argc, char** argv)
{
QApplication app(argc, argv);
dlgjanela janela;
janela.show();
return app.exec();
}




dlgjanela.h



//código para proteger multipla inclusao de headerss
#ifndef DLGJANELA_H
#define DLGJANELA_H



#include <QDialog>

//inicio da declaração prévia das classes

class QLabel;
class QPushButton;
class QVBoxLayout;
//como a classe não existe iremos fazer uma declaração pe+via para avisar que existe
//pois iria dar um erro de compilação



//protótipo da janela de teste

class dlgjanela: public QDialog
{


Q_OBJECT


public:
dlgjanela(QWidget* parent=0);





private slots:
void disable();



private:
//no private normalmente são declarações dos widgets que irão existir no dialogo
//os tipos de variavel devem existir ou estar presente npos headers
QLabel* label;
QPushButton* botao;
QVBoxLayout* layout;


};
#endif
//fim protecção multiplas inclusões




dlgjanela.cpp


#include <QtGui>//classe que contém uma
#include "dlgjanela.h"

//uma vez declarado os prototipos no header,implementamos os metodos das classes
dlgjanela::dlgjanela(QWidget* parent):QDialog(parent)
{

label=new QLabel("ola eliseu");
botao=new QPushButton("Sair");

//conexões
connect(botao,SIGNAL(clicked()),qApp,SLOT(disable( )));

layout= new QVBoxLayout;
layout->addWidget(label);
layout->addWidget(botao);
setLayout(layout);

}



void dlgjanela::disable()
{
botao->setEnabled(false);
}






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?

wysota
1st July 2008, 23:59
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.

wrproject
2nd July 2008, 00:11
and how i do that? i'm very noob.

wysota
2nd July 2008, 00:22
Run moc --help and read the help text. I really suggest you use qmake, though.

wrproject
2nd July 2008, 00:41
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?

wrproject
2nd July 2008, 00:58
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?

ChristianEhrlicher
2nd July 2008, 06:44
Add your header to HEADERS section in pro-File and rerun qmake
See also qmake Documentation (http://doc.trolltech.com/4.3/qmake-manual.html)

wrproject
2nd July 2008, 13:14
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.

wysota
2nd July 2008, 19:50
What part of "moc --help" did you not understand?

wrproject
3rd July 2008, 00:25
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.

wysota
3rd July 2008, 07:37
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.

wrproject
3rd July 2008, 15:04
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?

jpn
5th July 2008, 18:26
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".

wysota
6th July 2008, 09:29
There is always Eclipse, if one likes java-based apps...

markcole
9th July 2008, 20:30
I am pretty sure you need a semi-colon after the Q_OBJECT key word;



class yada: public nada
{
Q_OBJECT;

...

}

jacek
9th July 2008, 20:36
I am pretty sure you need a semi-colon after the Q_OBJECT key word
No, it isn't necessary.

markcole
9th July 2008, 20:44
No, it isn't necessary.

Good to know...