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. Questions about slots
Qt 6.11 is out! See what's new in the release blog

Questions about slots

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 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.
  • saxoalexS Offline
    saxoalexS Offline
    saxoalex
    wrote on last edited by
    #1

    Hi ! I'm sorry, in advance, for my bad english.

    I'm trying to run a program which use slots. Compilation works but when I run the program, he wait and don't do anything.

    Here we have the function :

    void Fenetre::Commencer()
    {
        main_display->setText("Bienvenue dans jhqqjhfqjf, le nouveau jeu video de la mort qui tue !\n");
        boutons[0]->setText("Commencer");
        boutons[1]->setText("Quitter ? Deja ?");
        boutons[2]->setText("Bouton vers la victoire");
        boutons[2]->setEnabled(false); //Parce que c'est marrant
    
        connect(boutons[0], SIGNAL(pressed()), this, SLOT(Etape(0,0)));
        connect(boutons[1], SIGNAL(pressed()), this, SLOT(reject()));
    }
    

    And his declaration on my class :

    public slots:
        void Etape(int from, int to);
    

    Can I put arguments in a slot ?
    Thank's !
    Alexandre.

    JKSHJ 1 Reply Last reply
    0
    • saxoalexS saxoalex

      Hi ! I'm sorry, in advance, for my bad english.

      I'm trying to run a program which use slots. Compilation works but when I run the program, he wait and don't do anything.

      Here we have the function :

      void Fenetre::Commencer()
      {
          main_display->setText("Bienvenue dans jhqqjhfqjf, le nouveau jeu video de la mort qui tue !\n");
          boutons[0]->setText("Commencer");
          boutons[1]->setText("Quitter ? Deja ?");
          boutons[2]->setText("Bouton vers la victoire");
          boutons[2]->setEnabled(false); //Parce que c'est marrant
      
          connect(boutons[0], SIGNAL(pressed()), this, SLOT(Etape(0,0)));
          connect(boutons[1], SIGNAL(pressed()), this, SLOT(reject()));
      }
      

      And his declaration on my class :

      public slots:
          void Etape(int from, int to);
      

      Can I put arguments in a slot ?
      Thank's !
      Alexandre.

      JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      Hi @saxoalex, and welcome!

      @saxoalex said in Questions about slots:

      Can I put arguments in a slot ?

      No. A slot can only get arguments from the signal.

      connect(boutons[0], SIGNAL(pressed()), this, SLOT(Etape(0,0)));
      

      This connection is wrong because:

      • The pressed() signal has no arguments, so it can only be connected to slots that also have no arguments.
      • You cannot write values/numbers in the connection. You can only write data types (such as "bool", "int", or "QString"). Example:
        • connect(slider, SIGNAL(valueChanged(int)), spinbox, SLOT(setValue(int))); // slider is a QSlider, spinbox is a QSpinBox
      connect(boutons[1], SIGNAL(pressed()), this, SLOT(reject()));
      

      This connection is OK.

      Compilation works but when I run the program, he wait and don't do anything.

      First, please read http://doc.qt.io/qt-5/signalsandslots-syntaxes.html

      You are using String-based connections, so your compiler cannot check them. You can change to Functor-based signals and let your compiler do the checks.

      // OK
      connect(boutons[1], &QPushButton::pressed,
              this, &Fenetre::reject);
      
      // Compiler error. The signal and slot are not compatible
      connect(boutons[0], &QPushButton::pressed,
              this, &Fenetre::Etape);
      
      // OK -- using a Lambda Expression
      connect(boutons[0], &QPushButton::pressed, [this] {
          this->Etape(0,0);
      });
      

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

      1 Reply Last reply
      3
      • saxoalexS Offline
        saxoalexS Offline
        saxoalex
        wrote on last edited by
        #3

        It work ! I understand.

        Thank you very much for this information !

        1 Reply Last reply
        1

        • Login

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