PDA

View Full Version : Handle QContextMenuEvent conflict



cia.michele
25th April 2011, 19:18
Good evening to all,
I'm a newbie of qt and I need some help for a strange event that I found during the developing of my system
I've create a two-level QTreeview (I've posted it in http://www.qtcentre.org/threads/40744-Hierarchical-TreeView?highlight=) and I need to use the QContextMenuEvent on the two QTreeview, and create the menù on the using class (I don't want create a fixed menu for the two QTreeview, I need to be able to change the menu relative to each one). Now I left the default configuration (Qt::DefaultContextMenu) and handled it in the using class (QMainWindow that use my control). It work fine in debugging mode, but in release mode ti failed given different errors:

ASSERT failure in QMutexLocker: "QMutex pointer is misaligned", file ..\..\include/QtCore/../../src/corelib/thread/qmutex.h, line 100 or

Starting C:\TestQT\Hgrid\Hierarchical\hierarchical-build-desktop\debug\hierarchical.exe...
... exited with code -1073741819 I think it could be a handling conflic of the two controls (I need to handle both of event; of the outher QTreeView but also the inner one), I tried to set the Qt::NoContextMenu policy but no better way (perhaps because I call the contextMenu on an object that isn't able to handle id?)

I don't know how I can pass the event handling to the outher QTreeview or resolve in some way this problem

Thanks for your time.

I hope to hearing from you soon :))

Michele

high_flyer
27th April 2011, 09:44
Its sounds you have a memory problem, either you are writing out of bounds, or using a dangling pointer.
Is your application threaded?

cia.michele
30th April 2011, 12:24
No, I don't use thread. You can see the code of my control at this link http://www.qtcentre.org/threads/40744-Hierarchical-TreeView?highlight= (Hierical QTreeview)

Thanks for your help

Michele

high_flyer
2nd May 2011, 10:47
See if these asserts fire:


void TableDelegate::setHideColumn(int column)
{
Q_ASSERT(column < 30);
colshided[column]=1;
}

void TableDelegate::setShowColumn(int column)
{
Q_ASSERT(column < 30);
colshided[column]=0;
}

void InternalTableDelegate::setHideColumn(int column)
{
Q_ASSERT(column < 30);
colshided[column]=1;
}

void InternalTableDelegate::setShowColumn(int column)
{
Q_ASSERT(column < 30);
colshided[column]=0;
}

cia.michele
2nd May 2011, 14:00
Dear high_flyer,
I added your code to the mine, and I isolated the HGrid component to the other software, creating a new small project that I attach.
If I request the context menu (in release mode or run debug mode) rapidly to the different QTreeView (outher and inner) and click onto the menu appared, after some click I obtain the "errore.png" window, I think relative to one of Q_Assert that I inserted. To know which of the 4 assert rised, i try to click "Debug with QTCreator" but I got the "nodebug.png" error dialog.
Other time, I got the "QMutex..." error that I post in previous posts yet, with "errQMutex.png" error dialog.

What else I should check?

Thanks a lot for your time.

Michele

high_flyer
2nd May 2011, 14:24
I think relative to one of Q_Assert that I inserted.
If the assert is caught, the message will contain the file and line number of the assert which caused the break.

Since you made a test project, and since it is crashing, just run it in a debugger, and see which line is crashing.

As I said in my first post, it looks like you are writing out of bounds, probably to your int array.
So have a look in your code to all the places where you reference that array, and make sure you surround that code with a check, so that you don't reference it outside its bounds.

cia.michele
2nd May 2011, 15:47
Thansk a lot high_flyer, but... which debugger? If I run my project by "Start debugging (F5)" from QTCreator, it no crash! How can I see the line code?
In one run of start debugging, it wrote:


Heap corruption detected at 00B33388
Heap corruption detected at 00B33388
Heap [hierarchical.exe]:
Heap: Free heap block b33380 modified at b33390 after it was freed.

..... exited with code 1073807364
Is there any other then I should check?

Thanks a lot for your time.

I'll check my code on that array

thanks.

Michele

high_flyer
2nd May 2011, 15:59
Ok, the problem as the debugger is saying, is a heap corruption, not a stack.
You are either reallocating memory on pointer that you haven't freed AND/OR doing some pointer arithmetic which is corrupting the pointer.
Make sure you free all the pointers you are allocating on the heap, and test the pointer for validity before using it.
Setting pointers to NULL when ever not initialized is recommended as well.