Results 1 to 6 of 6

Thread: scene->addItem() moans about QTimer ???

  1. #1
    Join Date
    Aug 2009
    Posts
    24
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default scene->addItem() moans about QTimer ???

    I want to move an QGraphicsItem gi in a scene being displayed. I use
    Qt Code:
    1. scene->removeItem(gi);
    2. gi->setPos(x, y);
    3. scene->addItem(gi);
    To copy to clipboard, switch view to plain text mode 
    At that point I get a warning
    Qt Code:
    1. QObject::startTimer: QTimer can only be used with threads started with QThread
    To copy to clipboard, switch view to plain text mode 
    and the view doesn't change. The warning totally foxes me. I have several threads in my program but gdb confirms all the basic GUI thread is active at this point. I don't want a timer, I want the view updated.

    What is going on?

    At first I had no removeItem addItem calls but that was gave the same warning.

    Thanks for any suggestions,
    Enno

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: scene->addItem() moans about QTimer ???

    Use a tracer or debugger to step trough the code.
    I don't think it is possible to tell where the error is with the information you have given.

    By the way, why do you remove an object from the scene in order to move its position?

  3. #3
    Join Date
    Aug 2009
    Posts
    24
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: scene->addItem() moans about QTimer ???

    Thanks. Will do some more debugging.

    Remove/add back only to see whether that made a difference. It didn't.

    Enno

  4. #4
    Join Date
    Aug 2009
    Posts
    24
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: scene->addItem() moans about QTimer ???

    Problem appears similar to what happens after calling update() from inside a paintEvent, against which the docs explicitly warn.

    I am calling update() from inside a mousePressEvent() and can't do much else because it is the mouse press that should triggers moving a QGraphicsRectItem to that position. The rect->setPos(x,y) causes the QTimer warning.

    After that a call view->update() does trigger a paintEvent but the rect does not get drawn at all.
    It is almost as if the view does not notice the scene change and hence skips repainting.

    Is this related to the new GraphicsItemFlags introduced in Qt 4.6. Before that things were working fine.

    I am still puzzled.
    Enno

  5. #5
    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: scene->addItem() moans about QTimer ???

    You rarely need to call update() manually. If you just change the position of the item, update() is not required, setPos() will suffice. Just make sure it is all done from the GUI thread.
    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.


  6. #6
    Join Date
    Aug 2009
    Posts
    24
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: scene->addItem() moans about QTimer ???

    You put your finger on the sore spot: new scene in non-GUI thread. The docs warned me, you warned me but I did.
    Thanks.

Similar Threads

  1. Use a QTimer in a Qt-non-GUI app.
    By hakermania in forum Newbie
    Replies: 11
    Last Post: 29th August 2010, 11:36
  2. Segmentation Faul using addItem (QListWidget)
    By gnusar in forum Qt Programming
    Replies: 3
    Last Post: 8th November 2008, 10:27
  3. QListWidget::addItem and display immediately
    By vlg789 in forum Qt Programming
    Replies: 6
    Last Post: 24th September 2007, 16:30
  4. "userdata" field in addItem in QComboBox
    By amulya in forum Qt Programming
    Replies: 1
    Last Post: 6th September 2007, 13:15
  5. Creating a scene from piece of another scene
    By maverick_pol in forum Qt Programming
    Replies: 3
    Last Post: 23rd August 2007, 18:51

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.