PDA

View Full Version : QGraphicsItem itemChanged() for ItemPositionHasChanged not working for Release



nileshsince1980
7th April 2010, 07:56
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

Lykurg
7th April 2010, 08:23
Have you QGraphicsItem::ItemSendsScenePositionChanges activated?

nileshsince1980
7th April 2010, 08:45
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.

Lykurg
7th April 2010, 09:29
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.

wysota
7th April 2010, 09:34
What is your code for itemChanged()?

nileshsince1980
7th April 2010, 10:08
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.


QVariant Node::itemChange(GraphicsItemChange change, const QVariant &value)
{
switch (change) {
case ItemPositionHasChanged:
foreach (Edge *edge, edgeList)
edge->adjust();
graph->itemMoved();
break;
default:
break;
};

return QGraphicsItem::itemChange(change, value);
}

wysota
7th April 2010, 10:14
And how do you know it doesn't get called?

nileshsince1980
7th April 2010, 10:26
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.

wysota
7th April 2010, 10:39
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)?

nileshsince1980
7th April 2010, 11:04
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


// Paints the item.
void RectItem :: paint(QPainter * painter, QStyleOptionGraphicsItem const * option, QWidget * widget)
{
Q_UNUSED(widget);

painter->setPen(Qt::black);
painter->setBrush(brush);
if (option->levelOfDetail > 2.)
painter->drawRects(&squareRect, 1);
else
painter->fillRect(squareRect, brush);
}


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.

wysota
7th April 2010, 11:08
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.

nileshsince1980
7th April 2010, 11:12
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.

wysota
7th April 2010, 11:39
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.

spud
7th April 2010, 14:35
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.

nileshsince1980
8th April 2010, 07:14
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. :confused:

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.

nileshsince1980
8th April 2010, 08:16
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