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. Some questions about loop in QWidget
Forum Updated to NodeBB v4.3 + New Features

Some questions about loop in QWidget

Scheduled Pinned Locked Moved General and Desktop
13 Posts 3 Posters 3.6k 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.
  • E Offline
    E Offline
    eiao
    wrote on 29 Jul 2013, 06:43 last edited by
    #1

    Hello``
    i creat a class widget(come from QWidget)
    put go() in widget::widget()
    @go()
    {
    while(on)
    {
    ...
    repaint();
    QApplication::processEvents();
    }
    }@

    also put something in closeEvent

    @ void Widget::closeEvent(QCloseEvent *e)
    {
    running=on=false;
    e->accept();
    //this->deleteLater();
    }@
    if i run this,and put alt-F4
    the window is hidden,but the pro is still runing unless i push the stop buttom in Qt creator.
    why?

    if there is no go() in widget::widget() , the pro can close.
    and i put this->deleteLater(); in closeEvent widget::~widget runs twice!
    ~widget be runned only widget be deleted. why it runs twice?
    thank you for help

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dbzhang800
      wrote on 29 Jul 2013, 06:56 last edited by
      #2

      Hi, you can use a QTimer to periodically do something, instead of using while loop.

      1 Reply Last reply
      0
      • E Offline
        E Offline
        eiao
        wrote on 29 Jul 2013, 06:59 last edited by
        #3

        [quote author="1+1=2" date="1375080995"]Hi, you can use a QTimer to periodically do something, instead of using while loop.[/quote]

        thank you, but QTimer doesn't meet my requirments.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dbzhang800
          wrote on 29 Jul 2013, 07:09 last edited by
          #4

          Hi, can you tell us your requirments ? I don't think that the things can be done in while loop in GUI thread can not be achieved with QTimer. And I also notice that you called repaint() manully, which seems not a good idea too.

          1 Reply Last reply
          0
          • E Offline
            E Offline
            eiao
            wrote on 29 Jul 2013, 07:18 last edited by
            #5

            [quote author="1+1=2" date="1375081773"]Hi, can you tell us your requirments ? I don't think that the things can be done in while loop in GUI thread can not be achieved with QTimer. And I also notice that you called repaint() manully, which seems not a good idea too.

            [/quote]

            i want refresh screen with precision.

            1 Reply Last reply
            0
            • D Offline
              D Offline
              dbzhang800
              wrote on 29 Jul 2013, 07:34 last edited by
              #6

              You mean that you have tried following things and find they don't meet your requirments?

              1. QTimer instead of while-loop
              2. update() instead of repaint()
              1 Reply Last reply
              0
              • E Offline
                E Offline
                eiao
                wrote on 29 Jul 2013, 08:12 last edited by
                #7

                [quote author="1+1=2" date="1375083260"]You mean that you have tried following things and find they don't meet your requirments?

                1. QTimer instead of while-loop
                2. update() instead of repaint()[/quote]
                  thank you help
                  QTimer is not so precision
                  update i will try...
                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  dbzhang800
                  wrote on 29 Jul 2013, 08:23 last edited by
                  #8

                  Yes, QTimer is not so precision.

                  But afaik, you can not make it accurate with your following code too.
                  @
                  while(on)
                  {
                  ...
                  repaint();
                  QApplication::processEvents();
                  }
                  @

                  1 Reply Last reply
                  0
                  • E Offline
                    E Offline
                    eiao
                    wrote on 30 Jul 2013, 02:29 last edited by
                    #9

                    [quote author="1+1=2" date="1375086205"]Yes, QTimer is not so precision.

                    But afaik, you can not make it accurate with your following code too.
                    @
                    while(on)
                    {
                    ...
                    repaint();
                    QApplication::processEvents();
                    }
                    @[/quote]

                    you mean... processEvents may causes delay?

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      dbzhang800
                      wrote on 30 Jul 2013, 02:40 last edited by
                      #10

                      Yes, there are so many things needed to do by it, such as mousePressEvent/mouseMoveEvent/resizeEvent/closeEvent/...

                      1 Reply Last reply
                      0
                      • E Offline
                        E Offline
                        eiao
                        wrote on 30 Jul 2013, 02:43 last edited by
                        #11

                        [quote author="1+1=2" date="1375152030"]Yes, there are so many things needed to do by it, such as mousePressEvent/mouseMoveEvent/resizeEvent/closeEvent/...[/quote]

                        do you have any better ways?

                        1 Reply Last reply
                        0
                        • E Offline
                          E Offline
                          eiao
                          wrote on 30 Jul 2013, 02:45 last edited by
                          #12

                          [quote author="1+1=2" date="1375152030"]Yes, there are so many things needed to do by it, such as mousePressEvent/mouseMoveEvent/resizeEvent/closeEvent/...[/quote]

                          can i set events' priority for reflashing screen immediately?

                          1 Reply Last reply
                          0
                          • JKSHJ Offline
                            JKSHJ Offline
                            JKSH
                            Moderators
                            wrote on 30 Jul 2013, 07:21 last edited by
                            #13

                            What precision do you need?

                            [quote author="eiao" date="1375152344"]can i set events' priority for reflashing screen immediately?[/quote]You can set event priorities (see "Qt::EventPriority":http://qt-project.org/doc/qt-5.1/qtcore/qt.html#EventPriority-enum and "QCoreApplication::postEvent()":http://qt-project.org/doc/qt-5.1/qtcore/qcoreapplication.html#postEvent). But, high-priority events can only "jump queue" if the other events are still waiting to be processed. They cannot interrupt an event that has already started getting processed.

                            If your application has already started processing a low-priority event when a high-priority event arrives, your new high-priority event must still wait for the first one to finish.

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

                            1 Reply Last reply
                            0

                            1/13

                            29 Jul 2013, 06:43

                            • Login

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