Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. One signal to many slots (and not the other way around

One signal to many slots (and not the other way around

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 1.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DeanQt
    wrote on last edited by
    #1

    Dear all,

    Lets say for example I have a push button that, upon being clicked, clears five doubSpinBox'es.

    I could manually do this as follows:
    @ connect (ui->pushButton, SIGNAL (clicked()), ui->doubleSpinBox, SLOT(clear()));
    connect (ui->pushButton, SIGNAL (clicked()), ui->doubleSpinBox_2, SLOT(clear()));
    connect (ui->pushButton, SIGNAL (clicked()), ui->doubleSpinBox_3, SLOT(clear()));
    connect (ui->pushButton, SIGNAL (clicked()), ui->doubleSpinBox_4, SLOT(clear()));
    connect (ui->pushButton, SIGNAL (clicked()), ui->doubleSpinBox_5, SLOT(clear()));
    @

    Suffice it to say, it starts becoming untidy and cluttered repeating the same manual connect statements.

    I want to therefore do something like this. I want to code one connect statement that refers to a custom slot called "clear_values" which in turn clears all the double spin boxes:

    @connect (ui->pushButton, SIGNAL (clicked()), this, SLOT(clear_values()));

    void MainWindow::clear_values()
    {
    ui->doubleSpinBox->clear();
    ui->doubleSpinBox_2->clear();
    ui->doubleSpinBox_3->clear();
    ui->doubleSpinBox_4->clear();
    ui->doubleSpinBox_5->clear();
    }
    @

    However the code above doesnt work, why not?

    PS: I am NOT looking for Signal mapper. Signal mapper is even more tedious and only comes in handy when there are many signals to one or more slots.

    1 Reply Last reply
    0
    • T Offline
      T Offline
      t3685
      wrote on last edited by
      #2

      What errors are you getting? This code should work.

      1 Reply Last reply
      0
      • JKSHJ Offline
        JKSHJ Offline
        JKSH
        Moderators
        wrote on last edited by
        #3

        Hi,

        Is clearValues() declared as a slot?

        After you added clearValues() as a slot, did you clean your project, re-run qmake, and rebuild your project?

        P.S. Always describe what you mean by "doesn't work", and provide any error messages that you see. The term "doesn't work" by itself cannot help your readers figure out the problem.

        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved