Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 3

Qt-interest Archive, March 2007
QObject connect trouble


Message 1 in thread

Hello,

I think I'm missing something with the 'connect' thing between two classes.

I have an UI form, in which I have some code :

class BoardWindow : public QMainWindow, public Ui::BoardWindow
{
        Q_OBJECT
        ...
        Myclass *myclass;
}

BoardWindow::BoardWindow( QWidget *parent , Qt::WindowFlags flags ) 
: QMainWindow( parent,  flags )
{
        myclass = new Myclass(this);
        connect(ui.myButton,SIGNAL(pressed()), myclass, SLOT(slotMyAction()));
        ...
}


And I have my working class

class Myclass : public QObject
{
//      Q_OBJECT
public:
        Myclass(BoardWindow *bw);
        ~Myclass();
 
public slots:
        void slotMyAction();
...

}

This code does not work, because at run time I get an error :
        Object::connect: No such slot QObject::slotMyAction()
        Object::connect: (sender name: 'myButton')



I have tried to uncomment the Q_OBJECT in Myclass definition, but the
compile produces errors at linking step :
        Myclass.o : in the function "Myclass"
        myclass.cpp : xx undefined reference to "vtable for Myclass"
        Myclass.o : in the function "~Myclass"
        myclass.cpp : yy undefined reference to "vtable for Myclass"


What am I missing ?
Thanks in advance

--
 [ signature omitted ] 

Message 2 in thread

eb schrieb:
> Hello,
> 
> I think I'm missing something with the 'connect' thing between two classes.
> 
> I have an UI form, in which I have some code :
> 
> class BoardWindow : public QMainWindow, public Ui::BoardWindow
> {
>         Q_OBJECT
>         ...
>         Myclass *myclass;
> }
> 
> BoardWindow::BoardWindow( QWidget *parent , Qt::WindowFlags flags ) 
> : QMainWindow( parent,  flags )
> {
>         myclass = new Myclass(this);
>         connect(ui.myButton,SIGNAL(pressed()), myclass, SLOT(slotMyAction()));
>         ...
> }
> 
> 
> And I have my working class
> 
> class Myclass : public QObject
> {
> //      Q_OBJECT
> public:
>         Myclass(BoardWindow *bw);
>         ~Myclass();
>  
> public slots:
>         void slotMyAction();
> ...
> 
> }
> 
> This code does not work, because at run time I get an error :
>         Object::connect: No such slot QObject::slotMyAction()
>         Object::connect: (sender name: 'myButton')
> 
> 
> 
> I have tried to uncomment the Q_OBJECT in Myclass definition, but the
> compile produces errors at linking step :
>         Myclass.o : in the function "Myclass"
>         myclass.cpp : xx undefined reference to "vtable for Myclass"
>         Myclass.o : in the function "~Myclass"
>         myclass.cpp : yy undefined reference to "vtable for Myclass"
> 
> 
> What am I missing ?
A qmake run after you added Q_OBJECT

Christian Ehrlicher

--
 [ signature omitted ] 

Message 3 in thread

Christian Ehrlicher wrote:


> A qmake run after you added Q_OBJECT
> 
> Christian Ehrliche


Yes, it worked.
Thanks

--
 [ signature omitted ]