Results 1 to 3 of 3

Thread: connect on a popup

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

    Default connect on a popup

    Hi I have a button in mymainform connect to a SLOT (that open a popup) where inside this I set and show many checkBox; I'd like conenct every checkBox to another SLOT; but I'like avoid 8 connect (for each checkBox). I try this that compile and no mesage error, but the SLOT don't starts....
    Qt Code:
    1. //constructor of myMainForm...
    2. connect(popup, SIGNAL(clicked()), this, SLOT(setOption()));
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void myMainForm::setting() {
    2. c0 = new QCheckBox(vbox0);
    3. c1 = new QCheckBox(vbox1);
    4. ........................................
    5. popup->show();
    6. }
    To copy to clipboard, switch view to plain text mode 
    Regards

  2. #2
    Join Date
    Jan 2006
    Location
    La Spezia,Italy
    Posts
    77
    Thanks
    9
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: connect on a popup

    Hi,I haven't exactly understood the code you posted,however I tell you what I have understood.

    Qt Code:
    1. //constructor of myMainForm...
    2. connect(popup, SIGNAL(clicked()), this, SLOT(setOption()));
    To copy to clipboard, switch view to plain text mode 
    I suppose you want to use this single connection instead of the 8 connections for each button,is it right?
    For what I know, it can't work because it's not the popup that emits the clicked() signal but are the buttons. If you want that your popup emits the clicked signal, you have to call it via a slot invoked by the clicked signal emitted from the buttons,:
    Qt Code:
    1. //In the popup constructor
    2. connect(buttonN,SIGNAL(clicked()),this,SLOT(emitclicked())); //8 times,for each button
    To copy to clipboard, switch view to plain text mode 
    and then:
    Qt Code:
    1. void Popup::emitclicked(){emit clicked();}
    To copy to clipboard, switch view to plain text mode 

    Another way is to organize the buttons inside an array,in this way you can spare lines of code
    Qt Code:
    1. //inside Mainform
    2. QVector<Button*> buttons;
    3. for(int i=0;i<8;i++){
    4. buttons[i]=new Button(...);
    5. connect(buttons[i],SIGNAL(clicked()),this,SLOT(setOption()));
    To copy to clipboard, switch view to plain text mode 

  3. #3
    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 on a popup

    Quote Originally Posted by vratojr
    Qt Code:
    1. //In the popup constructor
    2. connect(buttonN,SIGNAL(clicked()),this,SLOT(emitclicked())); //8 times,for each button
    To copy to clipboard, switch view to plain text mode 
    and then:
    Qt Code:
    1. void Popup::emitclicked(){emit clicked();}
    To copy to clipboard, switch view to plain text mode 
    This will work too:
    Qt Code:
    1. connect( buttonN, SIGNAL( clicked() ), this, SIGNAL( clicked() ) );
    To copy to clipboard, switch view to plain text mode 

  4. The following user says thank you to jacek for this useful post:

    vratojr (12th April 2006)

Similar Threads

  1. Popup notification window issues on Mac
    By alexandersv in forum Qt Programming
    Replies: 2
    Last Post: 20th April 2012, 11:15
  2. A signal/slot connect isn't working.
    By Daimonie in forum Qt Programming
    Replies: 6
    Last Post: 15th February 2009, 22:55
  3. multi level menu popup
    By MrGarbage in forum Qt Programming
    Replies: 1
    Last Post: 28th September 2007, 08:06
  4. Replies: 5
    Last Post: 28th August 2006, 14:36
  5. Can't close my popup
    By Jimmy2775 in forum Qt Programming
    Replies: 2
    Last Post: 11th July 2006, 09:10

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.