Results 1 to 16 of 16

Thread: QGraphicsItem itemChanged() for ItemPositionHasChanged not working for Release

  1. #1
    Join Date
    Sep 2007
    Location
    Pune, India
    Posts
    60
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question QGraphicsItem itemChanged() for ItemPositionHasChanged not working for Release

    Hi All,

    I am using QGraphicsView/Scene architecture to drawing items. I have added rectangles using QGraphicsItem and there are lines drawn between them. I want to move the lines are per rectangle changes its position using Mouse drag. Its like 'Elastic Nodes" app. in sample code. My app. works fine for Debug version on Windows XP but same code doesnt work for release version. I am not able to get itemChanged() event for ItemPositionHasChanged for Release.

    Please tell me the solution.

    Thanks in advance.

    Nilesh

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QGraphicsItem itemChanged() for ItemPositionHasChanged not working for Release

    Have you QGraphicsItem::ItemSendsScenePositionChanges activated?

  3. #3
    Join Date
    Sep 2007
    Location
    Pune, India
    Posts
    60
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsItem itemChanged() for ItemPositionHasChanged not working for Release

    Thanks for your reply ..

    Can you tell me how to activate QGraphicsItem::ItemSendsScenePositionChanges ?
    I am using QT 4.5.1 version.
    Also I have noticed this problem for 'Elastic Nodes' example's Release version as well.

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QGraphicsItem itemChanged() for ItemPositionHasChanged not working for Release

    Hmm, this flag was introduced in 4.6... Then I can't think of any case why in your release version it doen't work. Sorry.

  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: QGraphicsItem itemChanged() for ItemPositionHasChanged not working for Release

    What is your code for itemChanged()?
    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
    Sep 2007
    Location
    Pune, India
    Posts
    60
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsItem itemChanged() for ItemPositionHasChanged not working for Release

    Same as in 'ElasticNode' example.
    which doesnt get called for Release version I am using QT 4.5.1. & Visual Studio 2008 on Windowz XP.
    Qt Code:
    1. QVariant Node::itemChange(GraphicsItemChange change, const QVariant &value)
    2. {
    3. switch (change) {
    4. case ItemPositionHasChanged:
    5. foreach (Edge *edge, edgeList)
    6. edge->adjust();
    7. graph->itemMoved();
    8. break;
    9. default:
    10. break;
    11. };
    12.  
    13. return QGraphicsItem::itemChange(change, value);
    14. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 7th April 2010 at 09:14. Reason: wrong bbcode tag usage

  7. #7
    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: QGraphicsItem itemChanged() for ItemPositionHasChanged not working for Release

    And how do you know it doesn't get called?

  8. #8
    Join Date
    Sep 2007
    Location
    Pune, India
    Posts
    60
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsItem itemChanged() for ItemPositionHasChanged not working for Release

    I have put some std::cout << "\nItemPositionHasChanged"; in this function, which doesnt get print in case of Release version but for Debug version it gets print.

  9. #9
    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: QGraphicsItem itemChanged() for ItemPositionHasChanged not working for Release

    Does any other std::cout get printed throughout your application in release mode? Did you remember to flush the stream (i.e. with std::endl)?

  10. #10
    Join Date
    Sep 2007
    Location
    Pune, India
    Posts
    60
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsItem itemChanged() for ItemPositionHasChanged not working for Release

    ya, other std::cout gets print. but as it seems event is not getting called I am not able to see the ItemPositionHasChanged string.
    Also as I have lot of rectagle getting drawn. so to improve performance initially I am drawing filled rect without border and then after some LevelOfDetails I am drawing border.
    the codei s below
    Qt Code:
    1. // Paints the item.
    2. void RectItem :: paint(QPainter * painter, QStyleOptionGraphicsItem const * option, QWidget * widget)
    3. {
    4. Q_UNUSED(widget);
    5.  
    6. painter->setPen(Qt::black);
    7. painter->setBrush(brush);
    8. if (option->levelOfDetail > 2.)
    9. painter->drawRects(&squareRect, 1);
    10. else
    11. painter->fillRect(squareRect, brush);
    12. }
    To copy to clipboard, switch view to plain text mode 

    But above code also seems not working for Release version. I am not able to see border after zoom-in operations when levelOfDetails > 2.

    its very strange as same code works in Debug version.
    Last edited by nileshsince1980; 7th April 2010 at 10:28.

  11. #11
    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: QGraphicsItem itemChanged() for ItemPositionHasChanged not working for Release

    Please use proper bbcode tags in your posts.

    Make sure that you are actually running the right binary (i.e. that it has been rebuilt with your changes). It's not possible that an arbitrary method is called in debug mode and ignored in release mode.

  12. #12
    Join Date
    Sep 2007
    Location
    Pune, India
    Posts
    60
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsItem itemChanged() for ItemPositionHasChanged not working for Release

    Ho Wysota,

    I am too feeling the same way as you. I have tried cleaning and rebuilding the app. , checking the lib. for Debug/Release version. But nothing seems worked.
    If possible Can you just try to compile 'ElasticNode' example from Sample Code of QT 4.5.1 with VS2008 on Windows XP and see this effect.

    Thanks in advance.

  13. #13
    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: QGraphicsItem itemChanged() for ItemPositionHasChanged not working for Release

    I don't use VS2008 but the compiler is really irrelevant here. The elastic nodes example works fine and that's the sufficient proof that the method gets called.

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

    nileshsince1980 (8th April 2010)

  15. #14
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGraphicsItem itemChanged() for ItemPositionHasChanged not working for Release

    This is just a wild guess, but could it be that the release version of your program version loads the 4.6 Qt dlls at runtime? That would explain the effect. Check your paths or debug the release version in MSVC and check the output pane.

    EDIT:
    This also explains the problems with levelOfDetails, because this variable isn't set anymore in 4.6.

    There were some major performance tweaks of the Graphics View Framework between 4.5 and 4.6 and the Qt developers decided to change the default behaviour to "Don't pay for what you don't use". This means that any code relying on items sending updates of their position, or using levelOfDetail will not work as expected with the 4.6 dlls.
    Last edited by spud; 7th April 2010 at 13:43.

  16. The following user says thank you to spud for this useful post:

    nileshsince1980 (8th April 2010)

  17. #15
    Join Date
    Sep 2007
    Location
    Pune, India
    Posts
    60
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsItem itemChanged() for ItemPositionHasChanged not working for Release

    Hi All,
    Thanks for your suggestion.

    After taking lot of trial and error, I have got the solution of this Release version problem. On my computer, whenever I use to run 'ElasticNodes' example from QtDemo.exe then it runs fine & when I run that same exe ('ElasticNodes') from clicking on it from Windows Explorer it is not running as per expected.

    So when I copied my QT app's exe into Qt's bin folder & then executes from bin dir. then it runs fine. So I changed PATH variable & set QT's bin dir. path at very first position (i.e. PATH=C:\Qt\bin; %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\Sy stem32\Wbem;<other paths> ). Now it works fine.

    It might be because of some Release version DLLs clashing with other path’s present in PATH variable.
    Last edited by nileshsince1980; 8th April 2010 at 06:33.

  18. #16
    Join Date
    Sep 2007
    Location
    Pune, India
    Posts
    60
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsItem itemChanged() for ItemPositionHasChanged not working for Release

    Hi All

    I got the exact cause for Release version. I had installed MIKeTex 2.8 which intern installs Qt's some Dlls ( I dont know how ? but the DLLs are find in MIKTEx2.8 bin's dir. are QtCore4.dll, QtGui4.dll, QtScript4.dll, QtXml4.dll) into its bin folder. and in my PATH variable MIKTex2.8's bin dir. path is stored before QT's bin dir. path.

    So for Release version my QT app used to take DLLs from MIKTex2.8's bin dir rather than QT's bin dir.

    Thanks,
    Nilesh

Similar Threads

  1. Casting QGraphicsItem child from QGraphicsItem
    By patrik08 in forum Qt Programming
    Replies: 3
    Last Post: 29th August 2008, 15:37
  2. Replies: 2
    Last Post: 28th June 2008, 16:31
  3. QMutex is not working in release mode
    By bitChanger in forum Qt Programming
    Replies: 3
    Last Post: 25th April 2007, 13:32
  4. itemChanged()
    By chaosgeorge in forum Qt Programming
    Replies: 1
    Last Post: 24th November 2006, 02:56
  5. When itemChanged is emitted, can the change type be detected?
    By johnny_sparx in forum Qt Programming
    Replies: 3
    Last Post: 7th April 2006, 17:29

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.