Results 1 to 4 of 4

Thread: [Help] QObject::connect

  1. #1

    Default [Help] QObject::connect

    I have the following function:

    void MainWindow::OpenWindow(char a) {
    Ui_Form_Usuario* wig;
    switch(a) {
    case 1: {
    wig = new Ui_Form_Usuario;
    break;
    }
    case 'b': {
    wig = new Ui_Form_Motorista
    break;
    }
    }
    QWidget* owig = new QWidget(this);
    wig->setupUi(owig);
    owig->show();
    }

    If I pass parameter in the connection, it is underlined with a line. (It compiles, but does not work out).

    QObject::connect(action_Usu_rio, SIGNAL(activated()), MainWindow, SLOT(OpenWindow()));

    If I put in the function as openWindow a= 'u', go right and it opens a form.

    help

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: [Help] QObject::connect

    probably you should rewrite you connection like this
    Qt Code:
    1. QObject::connect(wig->action_Usu_rio, SIGNAL(activated()), this, SLOT(OpenWindow()));
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Sep 2009
    Posts
    140
    Thanks
    4
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [Help] QObject::connect

    If you need to connect a SIGNAL to a SLOT with parameters, arguments must match.
    Dont write down their name since the connect failed.
    Qt Code:
    1. //good connection
    2. QObject::connect(sender, SIGNAL(mySignal(type1, type2)), receiver, SLOT(mySlot1(type1, type2)));
    3. /*wrong connection with argument names
    4. QObject::connect(sender, SIGNAL(mySignal(type1 arg1, type2 arg2)), receiver, SLOT(mySlot1(type1 arg1, type2 arg2))); */
    To copy to clipboard, switch view to plain text mode 

    Notice that you dont need to use them all :
    Qt Code:
    1. QObject::connect(sender, SIGNAL(mySignal(type1)), receiver, SLOT(mySlot2(type1)));
    To copy to clipboard, switch view to plain text mode 

    With a default parameter in your OpenWindow function, your connect should work

    I hope I understood your problem.

  4. #4
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [Help] QObject::connect

    did u miss Q_OBJECT macro ...?
    "Behind every great fortune lies a crime" - Balzac

Similar Threads

  1. QObject::connect stalls
    By arkain in forum Qt Programming
    Replies: 2
    Last Post: 26th April 2009, 00:26
  2. Problem in QObject::connect( ... ) with smart_ptr ( Boost )
    By kunalnandi in forum General Programming
    Replies: 1
    Last Post: 15th October 2008, 07:44
  3. Replies: 6
    Last Post: 21st September 2007, 13:51
  4. QObject::connect says "no such signal"
    By MistaPain in forum Qt Programming
    Replies: 3
    Last Post: 31st October 2006, 05:40
  5. QStringList in QObject::connect
    By DPinLV in forum Qt Programming
    Replies: 6
    Last Post: 6th September 2006, 17:01

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.