Results 1 to 5 of 5

Thread: How to add a parameter to a slot

  1. #1
    Join Date
    Apr 2008
    Location
    Fons Outre-Gardons
    Posts
    16
    Thanks
    2
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default How to add a parameter to a slot

    Hello,

    This is the first time I use Qt and I need an advice to perform the following task.
    With this loop, I display a combobox on each column of the first row of my QTableWidget.
    Qt Code:
    1. for (int col=0 ; col <= colonnes ; ++col)
    2. {
    3. QComboBox *moncombo = new QComboBox;
    4. moncombo->addItems(PL_variables);
    5. TableW->setCellWidget(0, col, moncombo);
    6. connect(moncombo, SIGNAL(activated(int)),this, SLOT(associate(int)));
    7. }
    To copy to clipboard, switch view to plain text mode 
    With connect(moncombo, SIGNAL(activated(int)),this, SLOT(associate(int))); I can transmet the index of the combo to the slot.

    My problem is that I also have to transmet the number of the column on which the signal had been sent.
    I guess I should to use the horizontalHeader function or something like that, but I don't really know how to do this.

    Thanks

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to add a parameter to a slot

    You could use QSignalMapper for this.

  3. #3
    Join Date
    Apr 2008
    Location
    Fons Outre-Gardons
    Posts
    16
    Thanks
    2
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to add a parameter to a slot

    Thanks for your quick answer Marcel. I didn"t know this class yet, I read the documentation right now...

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to add a parameter to a slot

    It would probably be wiser to use a custom delegate instead of cell widgets. It'll get awfully slow if you have more than 10 of them.

  5. #5
    Join Date
    Apr 2008
    Location
    Fons Outre-Gardons
    Posts
    16
    Thanks
    2
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to add a parameter to a slot

    Thank you for your advise Wysota. I'm currently learning Qt and custom delegates is the next chapter for me Normaly, they are only 8 of them, so it's not to slow to execute.

    I could finaly manage to retrieve the number of column as follow :
    Qt Code:
    1. for (int col=0 ; col <= colonnes ; ++col)
    2. {
    3. QComboBox *moncombo = new QComboBox;
    4. moncombo->addItems(PL_variables);
    5. moncombo->setObjectName(QString::number(col)); // the name of my combo is the number of my column
    6. TableW->setCellWidget(0, col, moncombo);
    7. connect(moncombo, SIGNAL(activated(int)),this, SLOT(associate(int)));
    8. }
    To copy to clipboard, switch view to plain text mode 

    The slot
    Qt Code:
    1. void MainWindow::associate(int index)
    2. {...
    3. int c = sender()->objectName().toInt();
    4. ...}
    To copy to clipboard, switch view to plain text mode 

    Regarding to the documentation, it's not a very correct way to do this... That's why I try to implement another solution using QSignalMapper.

    Thanks for your advices...

Similar Threads

  1. How to declare SLOT as a parameter to member function?
    By QPlace in forum Qt Programming
    Replies: 2
    Last Post: 17th July 2018, 00:41
  2. Object::connect: Parentheses expected, slot...
    By bnilsson in forum Qt Programming
    Replies: 5
    Last Post: 5th April 2008, 15:02
  3. Replies: 2
    Last Post: 8th October 2007, 15:02
  4. a Text Editor with line numbers...
    By fullmetalcoder in forum Qt Programming
    Replies: 47
    Last Post: 5th April 2006, 11:10
  5. signal slot conection using a string, not a SLOT
    By rianquinn in forum Qt Programming
    Replies: 6
    Last Post: 5th February 2006, 18:52

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.