Results 1 to 7 of 7

Thread: QApplication::processEvents lets me to run all pending commands for my widget?

  1. #1
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default QApplication::processEvents lets me to run all pending commands for my widget?

    I have a custom widget which is created being some parameters.
    I have :
    Qt Code:
    1. A_panel * a_panel = new A_panel(a_widget, parent, sizable );
    2. QApplication::processEvents(QEventLoop::AllEvents);
    3. a_panel->resize(parent->width()*float(tam_100_or_0)/100, parent->height()*float(tam_100_or_0)/100);
    To copy to clipboard, switch view to plain text mode 

    Ok. my 'A_panel' has three internal calls. The constructor calls a function and this one a last one, that sets a 'i_am_ready' variable to 'true'.
    the resizeevent has 'if i_am_ready!=true return', that is, until my widget is not ready I dont want to process any resize event.

    Ok. The last code fails, I have a resizeevent before the three functions be called.
    I have tried to use the processEvents, but without success.
    Any help or idea ? Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QApplication::processEvents lets me to run all pending commands for my widget?

    What is this processEvents() call of yours supposed to do? Returning from resizeEvent() doesn't cause your widget to prevent being resized. resizeEvent() is simply a notification for the application that the widget has been resized. As far as I know you can't prevent the resize itself even if you explicitly ignore() the event.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QApplication::processEvents lets me to run all pending commands for my widget?

    Sorry. I explain me just a little...
    I have a code to place some internal widgets and paint the widget. I call it from resizeevent if 'i_am_ready' is true.
    What I want to do is a way to be sure all my internal code was executed before continue.
    (My constructor calls three functions before it was ready )

    This is the reason to try 'processevents'. (not to avoid resizeevent).
    Thanks wy.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QApplication::processEvents lets me to run all pending commands for my widget?

    But what events do you expect your widget to process right after the constructor returns? Are you posting any events to the widget in the constructor?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QApplication::processEvents lets me to run all pending commands for my widget?

    You are going to send me to the .... excuse me for not explaining better.

    This is the psedo-code I have :
    Qt Code:
    1. A_panel() // constructor type 1
    2. { call generic_constructor}
    3. A_panel() // constructor type 2
    4. { call generic_constructor}
    5.  
    6. generic_constructor() {
    7. set some variables;
    8. i_am_ready=false;
    9. launch a timer of 1 milisecond interval to check if the parent_widget is already visible.it calls timer_slot_function
    10. }
    11. the timer_slot_function () {
    12. if (my_parent_visible) place_things() ;
    13. }
    14.  
    15. place_things() {
    16. I measure the size and other things of widget parent to set the size and position of this custom_widget
    17. i_am_ready=true; // finally I set 'i_am_ready' to true.
    18. }
    19.  
    20. resize_event() {
    21. qDebug()<<"Resize_event";
    22. if (i_am_ready) place_things }
    23. }
    To copy to clipboard, switch view to plain text mode 

    Due to some reasons I dont want to execute 'place_things' on undesirable resize_events . I control this using 'i_am_ready' variable.

    I have this code a_panel is the custom widget)
    Qt Code:
    1. A_panel * a_panel = new A_panel(a_widget, parent, sizable );
    2.  
    3. a_panel->resize(parent->width()*float(tam_100_or_0)/100, parent->height()*float(tam_100_or_0)/100);
    To copy to clipboard, switch view to plain text mode 

    And I discover I have a resize_event (showed by the qdebug) before all the last code is executed.
    ( that is: genericcontructor-timer-placethings).

    Ok, this is due to the timer... i know.

    I have just found that the problem is the timer i use...
    Sorry again .

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QApplication::processEvents lets me to run all pending commands for my widget?

    How about this:

    Qt Code:
    1. class MyWidget : public QWidget {
    2. public:
    3. MyWidget(QWidget *parent = 0) : QWidget(parent) {
    4. m_initialized = false;
    5. }
    6. protected:
    7. void placeThings() { ... }
    8. void showEvent(QShowEvent *se) {
    9. if(!m_initialized) {
    10. placeThings();
    11. m_initialized = true;
    12. }
    13. }
    14. private:
    15. bool m_initialized;
    16. };
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. The following user says thank you to wysota for this useful post:

    tonnot (18th January 2012)

  8. #7
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QApplication::processEvents lets me to run all pending commands for my widget?

    I'm going to consider it. I'm sorry but I have to say you something on friday...
    Thanks again.

Similar Threads

  1. Pending network replies won't let program to quit
    By novichkov in forum Qt Programming
    Replies: 0
    Last Post: 4th August 2010, 20:28
  2. QCop - QApplication::ProcessEvents()
    By QbelcorT in forum Qt for Embedded and Mobile
    Replies: 5
    Last Post: 1st March 2009, 16:58
  3. Cancelling a pending database insert
    By innerhippy in forum Qt Programming
    Replies: 3
    Last Post: 30th October 2008, 09:53
  4. Problems with QApplication::processEvents()
    By Winni in forum Qt Programming
    Replies: 15
    Last Post: 5th January 2008, 20:31
  5. Lets build a network
    By sunil.thaha in forum General Discussion
    Replies: 5
    Last Post: 16th April 2007, 08:42

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.