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. What are the differences between qt's slot function and regular function during execution?
Forum Updated to NodeBB v4.3 + New Features

What are the differences between qt's slot function and regular function during execution?

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 5 Posters 609 Views 2 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.
  • J Offline
    J Offline
    John Van
    wrote on last edited by
    #1

    Hello everyone,
    I have a function that controls the output of the collection card, which can be successfully executed in the constructor of the widget, but fails in the slot function of qpushButton. This function does not require any other parameters.

    //toZero();
    	//QtConcurrent::run(toZero);
    	//QTimer::singleShot(100, toZero);
    //All three writing methods were successfully executed
    ... 
    	connect(zero, &QPushButton::clicked, this, []() { toZero(); });//All three writing methods failed to execute
    
    Christian EhrlicherC 1 Reply Last reply
    0
    • J John Van

      Hello everyone,
      I have a function that controls the output of the collection card, which can be successfully executed in the constructor of the widget, but fails in the slot function of qpushButton. This function does not require any other parameters.

      //toZero();
      	//QtConcurrent::run(toZero);
      	//QTimer::singleShot(100, toZero);
      //All three writing methods were successfully executed
      ... 
      	connect(zero, &QPushButton::clicked, this, []() { toZero(); });//All three writing methods failed to execute
      
      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      There is no difference between a slot function and a 'normal' member function. Provide more code.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      J 1 Reply Last reply
      2
      • Christian EhrlicherC Christian Ehrlicher

        There is no difference between a slot function and a 'normal' member function. Provide more code.

        J Offline
        J Offline
        John Van
        wrote on last edited by John Van
        #3

        @Christian-Ehrlicher
        The function is hardware related, so a more detailed process cannot be provided. I can verify that tozero was executed.
        In addition,I found that the execution was successful in the slot function of QDdoubleSpinBox:: valueChanged, but failed in the slot function of QPushButton:: clicked. Are there any differences in the execution process between these two slot functions?

        JonBJ 1 Reply Last reply
        0
        • J John Van

          @Christian-Ehrlicher
          The function is hardware related, so a more detailed process cannot be provided. I can verify that tozero was executed.
          In addition,I found that the execution was successful in the slot function of QDdoubleSpinBox:: valueChanged, but failed in the slot function of QPushButton:: clicked. Are there any differences in the execution process between these two slot functions?

          JonBJ Online
          JonBJ Online
          JonB
          wrote on last edited by JonB
          #4

          @John-Van
          Hardware or not, it remains the case that there is nothing special about a function used as a slot. It is just a plain, normal C++ function, which can be called from a signal connection or directly with no difference. If you find a difference there is something different about where or when you are calling it, not the fact that it is a slot. You may also omit the slots declaration and still use it/any function for a signal connection.

          I don't know what you mean by "I found success in QDoubleSpinBox:: valueChanged and failure in QPushButton:: clicked". If you have some difference you want to highlight please supply some minimal example which illustrates it.

          1 Reply Last reply
          2
          • S Offline
            S Offline
            SimonSchroeder
            wrote on last edited by
            #5

            There is no difference between slot functions and regular functions (when used in connections). The only difference is that moc will enter slot functions into a list where you can look up all slots during runtime by using a string. This is related to the old way of Qt doing slots. It is not used anymore.

            However, valueChanged and clicked are not slots, but signals. Signals are C++ functions which are auto-generated by Qt (using moc). This is the actual implementation logic how to call different 'slots' (and here 'slot' means both functions declared as slots as well as regular functions used as slot).

            @John-Van said in What are the differences between qt's slot function and regular function during execution?:

            In addition,I found that the execution was successful in the slot function of QDdoubleSpinBox:: valueChanged, but failed in the slot function of QPushButton:: clicked.

            This most likely means that your connect is wrong. Please provide the code for the two different connects if you want help.

            1 Reply Last reply
            0
            • J.HilkJ Online
              J.HilkJ Online
              J.Hilk
              Moderators
              wrote on last edited by J.Hilk
              #6

              this

              connect(zero, &QPushButton::clicked, this, []() { toZero(); })
              

              should fail to compile, is toZero a free floating function ?


              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              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