I'm trying to find out the reason of the crash of my Qt application, the debug doesn't contain much information available hence the difficult to find the reason... after using breakpoints, the closest I found was the line the crash might be at w.show() call (the application's GUI frooze before any button or anything at all show up). My main function is exactly this:
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
// disable Window's maxminize button
const Qt::WindowFlags flags = w.windowFlags() ^ Qt::WindowMaximizeButtonHint;
w.setWindowFlags(flags);
w.show();
return a.exec();
}
when the line where w.show() is reached, the application starts (but not properly, the GUI frooze, as I mentioned before) and after several minutes I got a SEGFAULT and the debugger look like this:
How can I fix this? I'm on this has been days, trying to get the debugger give more information so that I can trace back the SEGFAULT reason but without the debugger information like this, I have no idea what to do.
My Qt version:
There are various ways to tackle such a problem, assuming you can't provide an MCVE:
Strip the elements of MainWindow one by one, first from the constructor, and see what creates the crash
If stripping elements from the constructor helps, then restore parts of it, and run the debugger to study what causes the freeze
Keep in mind that freezing in GUI programs usually means the event loop is blocked. If you're calling QApplication::processEvents() anywhere, consider removing that.
Finally, if everything fails, you're gonna have to go to a linux system, and recompile Qt in debug mode (debug + release never worked for me), and track the event loop and see, in code, what freezes your GUI.
The reason I'm recommending Linux is because gdb is great, and cdb is horrible at this. If you have VS enterprise, you could try its debugger too.
Good luck.
The part of original code that has a problem (fixed) :
// disable Window's maximize button (use bitwise [and-not]&~ and not [xor]^)
const Qt::WindowFlags flags = w.windowFlags() &~ Qt::WindowMaximizeButtonHint;
w.setWindowFlags(flags);
or that same effect can be achieved by:
w.setWindowFlag(Qt::WindowMaximizeButtonHint, false);
Found solution!
Hope it's useful to anyone with same issue:
In the debug messages I found out the crash was result from GBIEH.dll dll. Googling it I found it's related to internet banking (I guess when my application tried to use that dll the IB's application take this as a kind of attack hence the crash, my guess). I just removed the internet banking programa and the application worked fine.
Related
I'm writing a c++ application that creates a GTK3 window at some point, while also running X11 code in other places.
For the pure X11 part i'm using XOpenDisplay() to open a display.
Running the X11 part and opening a GTK window afterwards works fine. Also running the X11 part multiple times is no problem as i release the display there using XCloseDisplay.
The problem i'm facing occurs when i try to run the X11 code after gtk has been initialized (to be more specific, calling XOpenDisplay() after the gtk initialization).
I'm suspecting that after running gtk_init() the display is never being released, even after gtk_main_quit().
I didn't find anything about deinitialization in the gtk3 documentation. Is there any way to propperly deinitialize gtk or free the display in another way?
The solution was completely unrelated. I was setting the DISPLAY environment variable twice by accident. Apparently gtk can handle this but XOpenDisplay crashes.
I have added a test to only set it once, now everything works. Perhaps gtk does propperly deinitialize after gtk_main_quit()
Qt 4.7.1
I have a qttest setup which has until recently been performing well. I have encountered, and dealt with, the need to interact with modal dialogs by using singleshot timers.
However, I am now seeing the opposite behaviour; calls such as QFileDialog::getSaveFileName are returning straight away with no display of the dialog. This is since I performed a merge so I assume there is some code or build change behind it, but it isn't the function call itself.
As far as example code goes, I can't post my whole framework or AUT but the consider the following inside a test function:
QMessageBox::StandardButton button = QMessageBox::question(NULL,"Thing",
"Do you want to do a thing?",
QMessageBox::StandardButton::Yes | QMessageBox::StandardButton::No);
The call returns straight away and button is set to NoButton. I should add that there is a bit of a framework around my tests and I manually start each test with QTest::qExec. (The framework has not changed, of that I'm sure)
Any ideas on what might be causing this?
Edit:
The eventloop started by the messagebox in the above example has quitNow set to true, which is causing exec to return straight away. I'm now looking for why this is set, in the meantime feel free to enlighten me!
This was due to calling qApp->exit() in my cleanup() function. There is no need to do this!
I have an SDI in which there is a:
AfxGetMainWnd()->PostMessageW(WM_CLOSE);
in the OnInitialUpdate() in the *View class.
The application closes and a few seconds later a
"MFC Application has stopped working"
window appears with the option to
(a) Check online for a solution and close the program
(b) Close the program
(c) Debug the program
Can someone please tell me what I can do to get rid of this problem?
Get rid of the AfxGetMainWnd()->PostMessageW(WM_CLOSE). It's retarded.
Basically, it's closing the windows application immediately. It makes no sense to spin up an SDI MFC application that is going to do that. You might as well write a console application.
And yes, you need to learn how to use the debugger. I'm sure it is telling you exactly what is wrong.
I am opening a file in my application (in Windows) by double-clicking it. I am passing the file name as received through argument to my open logic. There I am calling showMaximized(), but it is not getting picked up. The window that opens up is not maximized and defaultly located at the top-left corner of the screen.
Note that all this logic flow is through main() and hence showMaximized() is probably getting called before the event loop starts. Is this stopping the showMaximized() to work properly? If yes, how to solve this?
I also tried using QTimer::singleShot(0,...,...) (so as to let the event loop start) but this has even stopped the launching of the non-maximized screen.
PS: In Mac the screen is getting maximized as there it happens through event (QEvent::FileOpen)
Simplest workaround is use resize(800,600) before using showMaximized(). I have similar error in Qt 5.7.0 on Windows 8.1.
My answer is late but I write it in case it helps someone.
I am experimenting the same problem on Windows 11 with PyQt 6.
Initially I used the solution proposed by Vasilyev Eugene but it fails in some cases.
The best solution that I found was to use sigleShot with 1000ms of delay:
QtCore.QTimer.singleShot(1000, self.showMaximized)
The time is almost imperceptible to the final user, and you can experiment with lower values, except 0 apparently.
This solution is for PyQt but it is also applicable for Qt.
So on Windows I used a timer in the Application Windows.
I know it is smoehow ugly, but it works...
ApplicationWindow {
Timer {
id: fullscreenTimer
interval: 1000; running: false; repeat: false;
onTriggered: root.showFullScreen();
}
Component.onCompleted: {
fullscreenTimer.start();
}
}
The very first time a process calls ShowWindow, the show command is ignored and uses the command provided in the STARTUPINFO structure (which should correspond with the nCmdShow parameter in WinMain).
http://msdn.microsoft.com/en-us/library/windows/desktop/ms633548%28v=vs.85%29.aspx
This surprising behavior has a tendency to manifest itself in problems like the one you describe. You may be able to resolve it by simply issuing QT's showMaximized call twice if you don't want to use any Win32 API calls directly.
I want my application to open only one process, i.e. if the one process is already opened and the user want to open the exe again - it won't open another process.
how can I do it in Qt - linux?
10x!
What you're looking for is QtSingleApplication.
If you start another instance of your application, the first one will even get notified about it (you can pass whatever data structure you want).
I used it to bring the existing application to the front whenever another instance is started.
Use the following code in the main.cpp to prevent to run more than one instance of your application. I tested this code under Linux (in QtCreator) and it works (works for Windows too). I find this solution simple and easy to implement. The example is for a console application. The code remain the same for a GUI application, check the comments in the code.
//main.cpp
#include <QCoreApplication> //Console application
//#include <QApplication> //GUI application
#include <QSharedMemory>
#include <QDebug>
//Your QMainWindow derivated class goes here :
//#include "MainWindow.h"
int main(int argc, char *argv[])
{
QCoreApplication app( argc, argv );
app.processEvents();
//---- Check for another instance code snippet ----
//GUID : Generated once for your application
// you could get one GUID here: http://www.guidgenerator.com/online-guid-generator.aspx
QSharedMemory shared("62d60669-bb94-4a94-88bb-b964890a7e04");
if( !shared.create( 512, QSharedMemory::ReadWrite) )
{
// For a GUI application, replace this by :
// QMessageBox msgBox;
//msgBox.setText( QObject::tr("Can't start more than one instance of the application.") );
//msgBox.setIcon( QMessageBox::Critical );
//msgBox.exec();
qWarning() << "Can't start more than one instance of the application.";
exit(0);
}
else {
qDebug() << "Application started successfully.";
}
//---- END OF Check for another instance code snippet ----
// Only one instance is running, declare MainWindow
//MainWindow myMainWindow;
//myMainWindow.show();
//We enter the Qt Event loop here, we don't leave until the MainWindow is closed
//or the console application is terminated.
return app.exec();
}
This may not concern you, but I thought it would be useful to bring it up. I'm using QtSingleApplication myself and experienced some odd behavior a few days ago. QtSingleApplication doesn't seem to work under all circumstances. I made this expierence in windows, but depending on wether this is a windows specific bug or intended by the design of QtSingleApplication, it may also apply to linux.
Depending on the way you start your application multiple instances are possible. I made this experience when I did a testdrive of my application using my installer. The installer automatically starts the application after finishing. When I then started my application using the desktop link, I had two instances running. So the functionality of QtSingleApplication seems to depend on the way how (and by which user?) the application is started. The documentation is unclear about this. But I think usually one would expect this to work under all circumstances, if not stated otherwise.
So, if you don't need the extra functionality added by QtSingleApplication, QSystemSemaphore or QSharedMemory seems to be the better way to go.
Your application could check if a certain file in the user's home directory is present. If it is present, the application exits. If it is not there, the application creates it and continues. Of course, you might get a race condition if the user starts the application several times at once. But for most cases this simple solution should be sufficient.