Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [SOLVED]Pressing a button doesn't stop running the code withing it's on_click definition.
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]Pressing a button doesn't stop running the code withing it's on_click definition.

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 1.0k 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.
  • V Offline
    V Offline
    Vect0rZ
    wrote on 7 Sept 2014, 12:54 last edited by
    #1

    Hey folks,

    I wanted to print with @qDebug()@ all objects names when pressing a button. Here is the code:
    @void MainWindow::on_pushButton_2_clicked()
    {
    for(int i=0; i<objects.size(); i++){
    qDebug() << objects[i]->getObjectName();
    }
    }
    @

    But doing like this it doesn't stop looping?

    Thanks in advance.

    [Solved]

    The problem was that an advance() function was running in the object, that I was printing the objects name there too.

    1 Reply Last reply
    0
    • T Offline
      T Offline
      topse
      wrote on 7 Sept 2014, 13:35 last edited by
      #2

      Your problem is hard to understand... not many words, making not much sense. Nevertheless I try:

      As long as your "MainWindow::on_pushButton_2_clicked()" is running, your application cannot process more events, because the function is running in the context of the event-processing thread. So lets assume I understood your problem correctly, your second button cannot be used to "break" the execution of the for-loop.

      Best Regards,
      Tobias

      1 Reply Last reply
      0
      • V Offline
        V Offline
        Vect0rZ
        wrote on 7 Sept 2014, 13:49 last edited by
        #3

        Thanks for the reply!

        Excuse me for not explaining the problem in depth.

        Here is the expected output of pressing pushButton_2 if in the objects QVector i have 2 objects named: Object1 and Object2:
        @//Console output
        Object1
        Object2@
        But the output i get is
        @Object1
        Object2
        Object1
        Object2
        ...@

        About that you posted. Should't the function that is running in that event-processing thread stop when I release the button OR when the for loop is done looping through all objects in the QVector?

        1 Reply Last reply
        0
        • T Offline
          T Offline
          topse
          wrote on 7 Sept 2014, 16:55 last edited by
          #4

          Hi,
          I am not sure where to begin. My feeling is, you have a problem with the concept of event-loop, I will get to that in a moment. To clarify: you are wondering, that your event-handler is executed often instead of once?

          Concept of Event-Loop. This is your program-entry (??):

          @
          int main(int argc, char *argv[])
          {
          QApplication app(argc, argv);
          MyMainWindow window;
          window.show()
          return app.exec();
          }
          @

          "app.exec" enter the "Qt-Mainloop". This mainloop does something like this:

          @
          // Event-Loop:
          while (1)
          {
          waitForEvent();
          processEvent();
          }
          @

          So you see -- while an event is being processed, another event cannot be processed, until processing is done and the Event-Loop is reentered.

          Assuming that you are using "mouse-clicked", exactly one event should be fired when you press and then release the mouse-button over your button. Or have you used "press" and "release" signals?

          Now the question is, why your event-handler is called more than once. So there have to be multiple events in the queue which trigger your function.

          From your code I cannot see, why this is. Have you connected multiple signals to that slot? Can you give more code? Can you set a breakpoint in your handler-function and use the call-stack to find out, which events are triggering it?

          Best Regards,
          Tobias

          1 Reply Last reply
          0

          1/4

          7 Sept 2014, 12:54

          • Login

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