Unsolved Application crash on startup
-
I'm porting an application from Qt 4.8 to Qt 5.8, I've now got the application building with no issues, however on startup the application crashes.
I've single stepped using the debugger however I'm still none the wiser as to what the error that is displayed means. Its a very reliable crash and this is the code from main:
int main(int argc, char *argv[]) { enum APP_NAME { APP_NAME_BASE, APP_NAME_UI, APP_NAME_PARTS }; QScopedPointer<ExceptionHandlingQApplication> app(new ExceptionHandlingQApplication(argc, argv)); QString appName = QApplication::applicationName(); QStringList appNameList = appName.split("U"); Q_ASSERT_X(appNameList.length()==APP_NAME_PARTS, "main()", "Expecting U in application name!"); // Ensure the second element contains UI appNameList[APP_NAME_UI] = "UI"; /////////////////////////////////////////////////// // Get something logged so we know it started qDebug().noquote() << QDateTime::currentDateTimeUtc().toString("ddd dd MMM yyyy - hh:mm:ss ") << "////////////// Starting" << appName << "///////////////" ; qDebug() << "Version:" << PART_INFO << VERSION_INFO << BUILD_INFO << DATE_INFO; // Register custom debug handler // qInstallMessageHandler(Debug::customDebugProcessor); //This is very annoying. //The LoadLibrary call Qt uses will call this again //I'm re setting it before we actually start the app down below //But we could nuke the function once we're done by making it a return 0; //http://chadaustin.me/2009/03/disabling-functions/ //If any libs are loaded during runtime we may lose the hook :( SetUnhandledExceptionFilter(unhandled_handler); //suppress the "an error has occurred" boxes in release mode //The error handler will still catch the crash and dump, but we don't want customers to see it. //We have a batch wrapper around the exe which will restart it. #ifdef SUPPRESS_ERROR_DIALOG DWORD dwMode = SetErrorMode(SEM_NOGPFAULTERRORBOX); //to find out what the setting was SetErrorMode(dwMode | SEM_NOGPFAULTERRORBOX); //take what it was and OR in our new addition #endif SignalHandlerPointer previousSignalHandler; previousSignalHandler = signal(SIGABRT, SignalHandler); qmlRegisterType<QsltCursorShapeArea>("MyTools", 1, 0, "QsltCursorShapeArea"); qmlRegisterType<FeedControlItem>("MyTools", 1, 0, "FeedControlItem"); qmlRegisterUncreatableType<Calibration::CalibrationModel>("MyTools", 1, 0, "CalibrationModel", "Attempt to create CalibrationModel from QML"); qmlRegisterType<Process>("MyTools", 1, 0, "Process"); REGISTERMETATYPE(Process::ProcessState); qmlRegisterType<CacheProxyListModel>(appNameList[APP_NAME_BASE].toLatin1(), 1, 0, "CacheProxyListModel"); qmlRegisterType<ProxyProperty>(appNameList[APP_NAME_BASE].toLatin1(), 1, 0, "ProxyProperty"); // Is there a better place to register global metatypes? REGISTERMETATYPE(QStringList); // This is the UI QQuickView view;
With a breakpoint set on the last line, everything is ok, stepping over the last line results in this:
I've also just tried simplifying and doing just this:
int main(int argc, char *argv[]) { enum APP_NAME { APP_NAME_BASE, APP_NAME_UI, APP_NAME_PARTS }; QScopedPointer<ExceptionHandlingQApplication> app(new ExceptionHandlingQApplication(argc, argv)); QString appName = QApplication::applicationName(); QStringList appNameList = appName.split("U"); Q_ASSERT_X(appNameList.length()==APP_NAME_PARTS, "main()", "Expecting U in application name!"); // Ensure the second element contains UI appNameList[APP_NAME_UI] = "UI"; // This is the UI QQuickView view;
The result is the same:
This is also displayed in the Issues panel:
f:\dd\vctools\crt\crtw32\string\i386\strcmp.asm:82: error: Exception at 0x52b94280, code: 0xc0000005: read access violation at: 0x0, flags=0x0 (first chance) -
@SPlatten said in Application crash on startup:
I'm porting an application from Qt 4.8 to Qt 5.8
The first question would be why 5.8 rather than a more recent version?
-
@JonB , thats not my decision, its the newest version the company I'm on contract to is using.
-
@SPlatten well, have you tried stepping in (F11 on windows and QTC) instead of stepping over (F10) ?🤔
-
@J-Hilk I’ll take another look tomorrow, taking a break from it now.
-
@J-Hilk , back on it this morning and single stepped every line stepping into where possible.
Nothing looks wrong, I cannot single step into:
QQuickView view;
It still crashes with the same Exception Triggered dialog.
I then reduced the code even more:
int main(int argc, char *argv[]) { QApplication app(argc, argv); // This is the UI QQuickView view;
And this doesn't crash so it would appear to be something thats done in:
QScopedPointer<ExceptionHandlingQApplication> app(new ExceptionHandlingQApplication(argc, argv));
Which I replaced with just:
QApplication app(argc, argv);
I'm not sure why a QScopedPointer is used at all instead of just:
ExceptionHandlingQApplication app(argc,argv);
The header / prototype for the ExceptionHandlingQApplication:
class ExceptionHandlingQApplication : public QApplication { Q_OBJECT public: ExceptionHandlingQApplication(int& argc, char *argv[]); virtual ~ExceptionHandlingQApplication(); virtual bool notify( QObject* receiver, QEvent* event); };
And the constructor:
ExceptionHandlingQApplication::ExceptionHandlingQApplication(int& argc, char *argv[]) : QApplication(argc, argv) {}
I really don't see whats wrong with this?
I've also tried:
ExceptionHandlingQApplication app(argc, argv);
Still causes a crash:
Can anyone explain what is going on?
Looking at another version of the almost the same source for another project I could see a difference, in one of the headers the definition:
#define WIN32_LEAN_AND_MEAN 1
I added this to the project I'm working on and tested again, now there is no error....I've no idea why this fixes it.