PDA

View Full Version : error No such slot QMainWindow::open()



kavinsiva
12th August 2009, 06:40
hi,

When i am running the following program i am getting following error

Object::connect: No such slot QMainWindow::open()
pls help me to resolve this one


my win.h Header File

#ifndef WIN_H
#define WIN_H
#include<QtGui>
class win : public : QMainWindow
{
public:
win();
private slots:
void open();
private :
QPushButton *pb1;
};
#endif

my win.cpp file


#include"win.h"
#include<QtGui>
win::win()
{
setWindowTitle("test Window");
pb1=createLink(tr("& test"),SLOT(open()));
pb1->setVisible(true);
pb1->setGeometry(0,0,40,40);
pb1->setText("test");
QObject::connect(pb1,SIGNAL(pressed()),this,SLOT(o pen()));
}
void win::open()
{
setWindowTitle("event occured");
}

yogeshgokul
12th August 2009, 06:45
You forgot Q_OBJECT macro.

kavinsiva
12th August 2009, 06:52
hi ,

i placed Q_OBJECT macro after compiling i am getting following error

main.o: In function `main':
main.cpp:(.text+0x5e): undefined reference to `vtable for win'
main.cpp:(.text+0x67): undefined reference to `vtable for win'
main.cpp:(.text+0xa5): undefined reference to `vtable for win'
main.cpp:(.text+0xae): undefined reference to `vtable for win'
win.o: In function `win::win()':
win.cpp:(.text+0x9c): undefined reference to `vtable for win'
win.o:win.cpp:(.text+0xa3): more undefined references to `vtable for win' follow
collect2: ld returned 1 exit status
make: *** [testWin] Error 1

yogeshgokul
12th August 2009, 06:59
class win : public : QMainWindow

Replace this line with this:

class win : public QMainWindow



QObject::connect(pb1,SIGNAL(pressed()),this,SLOT(o pen()));

Replace this line with this:

QObject::connect(pb1,SIGNAL(pressed()),this,SLOT(o pen()));
Remove the space in O PEN.


void win: open()
Replace this line with

void win:: open()
Notice Scope Resolution Operator.

And you never allocated memory to QPushButton *pb1; So it will lead to crash.

wysota
12th August 2009, 08:39
Rerun qmake after adding the macro to the class.