Results 1 to 3 of 3

Thread: Multiple slots and signals

  1. #1
    Join Date
    Jul 2013
    Posts
    16
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Multiple slots and signals

    Dear All,

    I am newbie to Qt and found this forum very helpful whenever stuck in some problems. Today unfortunately i cannot find a suitable and matched answer to my question, so posting here for help.

    I have four sliders in my project and i wants to connect them with four respective Bytes of same array.

    connect(horizontalSlider_RED, SIGNAL(valueChanged(int)), this, SLOT(set_value_RED(int)));
    connect(horizontalSlider_GREEN, SIGNAL(valueChanged(int)), this, SLOT(set_value_GREEN(int)));
    connect(horizontalSlider_BLUE, SIGNAL(valueChanged(int)), this, SLOT(set_value_BLUE(int)));
    connect(horizontalSlider_WHITE, SIGNAL(valueChanged(int)), this, SLOT(set_value_WHITE(int)));

    In the set_value function they will not be processed just passed to another function with some other arguments. In the next function they will be like this

    command[3] = value_RED;
    command[4] = value_BLUE;
    command[5] = value_WHITE;
    command[6] = value_GREEN;

    If you see in the slider portion of code that i can only send one argument and cannot send 4 argument. Here i want to send the output of 4 sliders simultaneously to the next function (set_value function), so that it will be processed appropriately.


    Looking forward for a favorable response.

    Thanks

  2. #2
    Join Date
    Feb 2013
    Location
    India
    Posts
    153
    Thanks
    27
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Multiple slots and signals

    Please Paste your code for more understanding of your problem.

    and please briefly explain your question.

  3. #3
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Multiple slots and signals

    Hope this helps
    Qt Code:
    1. class SliderWidget : public QWidget
    2. {
    3. Q_OBJECT
    4. public:
    5. explicit SliderWidget(QWidget * parent = 0)
    6. : QWidget(parent)
    7. , mRed(new QSlider(Qt::Horizontal))
    8. , mBlue(new QSlider(Qt::Horizontal))
    9. , mWhite(new QSlider(Qt::Horizontal))
    10. , mGreen(new QSlider(Qt::Horizontal))
    11. , mRedValue(new QLabel("0"))
    12. , mBlueValue(new QLabel("0"))
    13. , mWhiteValue(new QLabel("0"))
    14. , mGreenValue(new QLabel("0"))
    15. , mColorValue(new QLabel("0x00000000"))
    16. {
    17. QGridLayout * gridLayout = new QGridLayout(this);
    18.  
    19. gridLayout->addWidget(new QLabel("Red"), 0, 0, 1, 1);
    20. gridLayout->addWidget(new QLabel("Blue"), 1, 0, 1, 1);
    21. gridLayout->addWidget(new QLabel("White"), 2, 0, 1, 1);
    22. gridLayout->addWidget(new QLabel("Green"), 3, 0, 1, 1);
    23. gridLayout->addWidget(new QLabel("Color"), 4, 0, 1, 1);
    24.  
    25. gridLayout->addWidget(mRedValue, 0, 1, 1, 1);
    26. gridLayout->addWidget(mBlueValue, 1, 1, 1, 1);
    27. gridLayout->addWidget(mWhiteValue, 2, 1, 1, 1);
    28. gridLayout->addWidget(mGreenValue, 3, 1, 1, 1);
    29. gridLayout->addWidget(mColorValue, 4, 1, 1, 1);
    30.  
    31. gridLayout->addWidget(mRed, 0, 2, 1, 1);
    32. gridLayout->addWidget(mBlue, 1, 2, 1, 1);
    33. gridLayout->addWidget(mWhite, 2, 2, 1, 1);
    34. gridLayout->addWidget(mGreen, 3, 2, 1, 1);
    35.  
    36. mRed->setRange(0, 255);
    37. mBlue->setRange(0, 255);
    38. mWhite->setRange(0, 255);
    39. mGreen->setRange(0, 255);
    40.  
    41. connect(mRed, SIGNAL(valueChanged(int)), SLOT(updateValues()));
    42. connect(mBlue, SIGNAL(valueChanged(int)), SLOT(updateValues()));
    43. connect(mWhite, SIGNAL(valueChanged(int)), SLOT(updateValues()));
    44. connect(mGreen, SIGNAL(valueChanged(int)), SLOT(updateValues()));
    45. }
    46.  
    47. private slots:
    48. void updateValues(void)
    49. {
    50. mRedValue->setText(QString::number(mRed->value()));
    51. mBlueValue->setText(QString::number(mBlue->value()));
    52. mWhiteValue->setText(QString::number(mWhite->value()));
    53. mGreenValue->setText(QString::number(mGreen->value()));
    54.  
    55. QString val;
    56. val += QString::number(mRed->value(), 16);
    57. val += "," + QString::number(mBlue->value(), 16);
    58. val += "," + QString::number(mWhite->value(), 16);
    59. val += "," + QString::number(mGreen->value(), 16);
    60. mColorValue->setText(val.toUpper());
    61. }
    62.  
    63. private:
    64. QSlider * mRed;
    65. QSlider * mBlue;
    66. QSlider * mWhite;
    67. QSlider * mGreen;
    68.  
    69. QLabel * mRedValue;
    70. QLabel * mBlueValue;
    71. QLabel * mWhiteValue;
    72. QLabel * mGreenValue;
    73.  
    74. QLabel * mColorValue;
    75. };
    To copy to clipboard, switch view to plain text mode 
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

Similar Threads

  1. Replies: 2
    Last Post: 18th April 2013, 13:15
  2. Signals and Slots
    By Maluko_Da_Tola in forum Newbie
    Replies: 3
    Last Post: 30th July 2010, 00:57
  3. regarding signals/slots
    By jjbabu in forum Qt Programming
    Replies: 2
    Last Post: 4th October 2007, 10:32
  4. Signals and slots
    By sylvarant in forum Newbie
    Replies: 4
    Last Post: 11th September 2007, 16:48
  5. Signals and Slots
    By merry in forum Qt Programming
    Replies: 4
    Last Post: 22nd February 2007, 09:11

Tags for this Thread

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.