Results 1 to 3 of 3

Thread: GUI parametres update in advance slot

  1. #1
    Join Date
    May 2013
    Posts
    2
    Platforms
    Windows
    Thanks
    1

    Default GUI parametres update in advance slot

    Hi,

    I try to update QLCDNumber value( which is placed, of course, out of QGraphicScene) in advance function, which is part of one of QGraphicsItem. Program breaks. Whereas if I place it for example in constructor everything is fine, but of course it works only once.

    Definition
    Qt Code:
    1. QLCDNumber *elevatorsCurrentLevelDisplayArray[5];
    2. {
    3. elevatorsCurrentLevelDisplayArray[0]=ui->elevator1;
    4. elevatorsCurrentLevelDisplayArray[1]=ui->elevator2;
    5. elevatorsCurrentLevelDisplayArray[2]=ui->elevator3;
    6. elevatorsCurrentLevelDisplayArray[3]=ui->elevator4;
    7. elevatorsCurrentLevelDisplayArray[4]=ui->elevator5;
    8. }
    9. QLCDNumber **elevatorsCurrentLevelDisplay = elevatorsCurrentLevelDisplayArray;
    To copy to clipboard, switch view to plain text mode 

    Here it works
    Qt Code:
    1. QGraphicsBuilding::QGraphicsBuilding(QLCDNumber **_elevatorsCurrentLevelDisplay)
    2. {
    3. (*mv_elevatorsCurrentLevelDisplay)[0].display(3);
    4. }
    To copy to clipboard, switch view to plain text mode 


    Here it breaks.
    Qt Code:
    1. void QGraphicsBuilding::advance(int step)
    2. {
    3. if (!step)
    4. return;
    5. //for(int i=0; i<m_building->m_numberElevators; i++)
    6. (*mv_elevatorsCurrentLevelDisplay)[0].display(3);
    7. addQGraphicsMen();
    8. m_building->simulation();
    9. updateCoordinates();
    10. updateParents();
    11. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: GUI parametres update in advance slot

    Get rid of all the pointers and the error will probably either go away by itself or will give you a clean reason of why it is not working (e.g. trying to access the pointer array before it is assigned proper data). If the first snippet of your code is your actual code then what you do is that you create a local array of pointers to QLCDNumber then you assign this array to another pointer and then you leave the scope, causing the first array to be deleted by the compiler and you are left with dangling pointer. As long as something overwrites the part of the stack where the array was declared (which most probably happens after you call a method or two causing the top of the stack to move), when you try to access data in the array that was deleted, your application crashes. Instead of this incorrect construction, declare a list of pointers to QLCDNumber as a member of your class and access it directly whenever you need it.
    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. The following user says thank you to wysota for this useful post:

    galvanize (14th May 2013)

  4. #3
    Join Date
    May 2013
    Posts
    2
    Platforms
    Windows
    Thanks
    1

    Default Re: GUI parametres update in advance slot

    Thank You very much. Now everything is fine.

Similar Threads

  1. QGraphicsItem::update(); vs scene()->update();
    By Lord_Navro in forum Newbie
    Replies: 1
    Last Post: 25th April 2013, 06:23
  2. QFileSystemModel - Incremental update/pre-emptive update
    By johnnyturbo3 in forum Qt Programming
    Replies: 0
    Last Post: 2nd September 2011, 13:56
  3. Replies: 3
    Last Post: 24th April 2011, 16:35
  4. Replies: 2
    Last Post: 29th September 2010, 17:44
  5. Replies: 0
    Last Post: 16th April 2010, 23:21

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
  •  
Qt is a trademark of The Qt Company.