Results 1 to 3 of 3

Thread: connect

  1. #1
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default connect

    I I have code this below but I have and error on 1th connect
    Qt Code:
    1. mywidget.cpp(113): error C2664: 'bool QObject::connect(const QObject *,const char *,const QObject *,const char *)' : cannot convert parameter 3 from 'myMainForm *' to 'const QObject *'
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. //constructor of MyWidget class
    2. w = (MainForm*)this->topLevelWidget();
    3. myw= (myMainForm*)this->topLevelWidget();
    4. connect(this, SIGNAL(myUpdate()), myw, SLOT(myUpdateWidgets()) );
    5. connect(this, SIGNAL(myUpdate()), w, SLOT(updateWidgets()) );
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. class MyWidget {
    2. MainForm* w;
    3. myMainForm* myw;
    4. }
    To copy to clipboard, switch view to plain text mode 
    The 2nd connect works properly; Why this error on 1th? Isn't it the same? Thanks
    Regards

  2. #2
    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: connect

    Quote Originally Posted by mickey
    The 2nd connect works properly; Why this error on 1th? Isn't it the same?
    No, they're not the same. In second snippet a forward declaration is enough, because compiler needs only information about the size. In the first one the whole class definition must be visible (i.e. you must add proper #include statement), because compiler needs to know whether it can cast myMainForm to QObject.

    Anyway, you don't need those casts (since both objects will be converted to QObject, before the connect() method is invoked). You can write it this way:
    Qt Code:
    1. w = this->topLevelWidget();
    2. connect(this, SIGNAL(myUpdate()), w, SLOT(myUpdateWidgets()) );
    3. connect(this, SIGNAL(myUpdate()), w, SLOT(updateWidgets()) );
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Posts
    976
    Thanks
    53
    Qt products
    Qt3
    Platforms
    Windows

    Default Re: connect

    Hi, cast (MainForm*) is necessary; otherwise occur this error:
    Qt Code:
    1. mywidget.cpp(70): error C2440: '=' : cannot convert from 'QWidget *' to 'MainForm *'
    To copy to clipboard, switch view to plain text mode 
    I didn't include "myMainForm"! Sorry please;
    Thanks
    Regards

Similar Threads

  1. A signal/slot connect isn't working.
    By Daimonie in forum Qt Programming
    Replies: 6
    Last Post: 15th February 2009, 22:55
  2. Replies: 12
    Last Post: 18th September 2008, 15:04
  3. connect problem QDialog
    By Zergi in forum Newbie
    Replies: 1
    Last Post: 1st January 2008, 13:36
  4. Replies: 5
    Last Post: 28th August 2006, 14:36

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.