QMessageBox closes application
-
@hobbyProgrammer said in connect() keeps crashing:
Do you guys have any idea what might causes the app to crash?
Take a debugger and look at the backtrace where exactly it crashes. Since you only show the connect to showContextMenu() and not it's implementation and you say it's crashing inside showContextMenu() we can't help any further.
-
@hobbyProgrammer said in connect() keeps crashing:
It fully walks through the slot(showContextMenu)
So, your slot is crashing, not connect()? connect() just connects signals and slots.
What does your slot do (show code)?
Do you have stack trace? -
hi
@hobbyProgrammer said in connect() keeps crashing:connect
most likely this will not solve the crash but its better to use New Signal Slot Syntax
connect(this, &MyClass::customContextMenuRequested, this, &MyClass::showContextMenu);
-
As @jsulm said, it's probably your slot that crashes. The reason for that assumption is that you don't specify a connection type and the default is a
Qt::AutoConnection
which in turn means aQt::DirectConnection
. That means your slot is called as soon as it is triggered. Perhaps something isn't quite ready at that point? Try specifyingQt:QueuedConnection
as the connection type and see if that helps.As @LeLev points out you may be better off using the new signal/slot syntax as long as there isn't any overloaded signal in place. If you keep using the old signal/slot syntax (perfectly valid) you may want to change the parameter type(s) to the pure non-qualified type in your connect statement (and only there). That is, instead of specifying const QPoint&, just specify QPoint. Also, if you have more than one parameter make sure that there's no space before or after the comma.
-
@LeLev said in connect() keeps crashing:
connect(this, &MyClass::customContextMenuRequested, this, &MyClass::showContextMenu);
I tried this, but it still doesn't come back from the showContextMenu. I inserted a qDebug() at the end of showContextMenu and that one does show up in the debugger, but the qDebug() i've put after the connect() doesn't show up in the debugger.
-
@hobbyProgrammer
There is something very odd here. If it genuinely does not execute the line after theconnect()
as you say, then (presumably) the connection would not be made so the slot would never be called and you would not seeshowContextMenu()
being called. Have a look again at your code/debug output, use a debugger breakpoint, etc. -
@hobbyProgrammer Then please show showContextMenu code or a stack trace, else we can only guess...
The thing is: connect() does not call showContextMenu, it just connects the signal to the slot. -
@jsulm It seems to print the qDebug() line before executing the connect(). And the app closes in the qeventloop.cpp.
while (!d->exit.loadAcquire()) processEvents(flags | WaitForMoreEvents | EventLoopExec);
I have no idea why it stops there.
-
@jsulm it also stops whenever I save a file. The saving part works perfectly, but afterwards it just closes down the app and it seems to be the same mystery as the showContextMenu.
I would like to think that it's the connect function, since they both use connect().
However I've connected about 20 actions like this and only 2 seems to close the app. I would expect them all to close down the app if it were the connect() function. -
@hobbyProgrammer As I said: connect() does not call the slots.
Why don't you simply use debugger to see where exactly it crashes? -
@hobbyProgrammer
@jsulm will know better than I, but I wouldn't have thoughtconnect()
would even callprocessEvents()
/the main event loop? -
@hobbyProgrammer Does it crash if you do not connect the slot?
And it would be helpful if you would post the stack trace after crash. -
@hobbyProgrammer said in connect() keeps crashing:
Whenever I use the debugger I don't even get the showContexyMenu(),
So what's the backtrace?
-
I'm not really familliar with the debugger... Does this provide the information you need?
-
@hobbyProgrammer If you post screen shots you should at least make sure the function signature on the bottom-right side are readable...
-
@hobbyProgrammer
It would be better if we could read the full function signatures at the bottom right, instead of left-truncated! Can't you drag the column resizer so we can see the full function name? You can make columns like Condition or Ignore much smaller. -
@hobbyProgrammer said in connect() keeps crashing:
qv.at(i)
It looks like you've created your vector on stack. What exactly does your slot do? Which vars do you access / try to access there?
If the connection fails, you would get an explicit warning / error message (which is obviously not the case)I'm sure, that it crashes because you did something wrong before or inside your slot function.