Hi
I have an application that builds and runs fine in Debug mode, but when ran in Release mode it produces a "Access violation reading location 0x...." error. I try to process the command line parameters passed to the application before constructing the QMainWindow and calling QApplication.exec(). I have put some qDebug() statements and it appears it crashes straight after I call any QString methods. It appears to me that there might be some linking errors but I can't seem to find the cause. Here's my main() function:
int main(int argc, char *argv[])
{
MyWindow *mw= 0;
qDebug() << s;
if(a.argc() > 1)
{
qDebug() <<"before check";
QString correctStr
= MyHelper
::getProgramStr();
qDebug() <<"str: " << correctStr;
qDebug() << a.arguments();
qDebug() << a.arguments().at(1);
QString res
= a.
arguments().
at(1).
toLower().
trimmed();
qDebug() << "arg: " << res;
//code below never reached in Release mode
//..........
}
else
{
//set errormessage
//.........
}
return a.exec();
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MyWindow *mw= 0;
QString s = QString("myHardCodedString").toLower().trimmed();
qDebug() << s;
if(a.argc() > 1)
{
qDebug() <<"before check";
QString correctStr = MyHelper::getProgramStr();
qDebug() <<"str: " << correctStr;
qDebug() << a.arguments();
qDebug() << a.arguments().at(1);
QString res = a.arguments().at(1).toLower().trimmed();
qDebug() << "arg: " << res;
//code below never reached in Release mode
//..........
}
else
{
QErrorMessage *error = new QErrorMessage();
//set errormessage
//.........
}
return a.exec();
}
To copy to clipboard, switch view to plain text mode
The last qDebug() message before the "Access violation" error in release mode is this one:
qDebug() << a.arguments().at(1);
qDebug() << a.arguments().at(1);
To copy to clipboard, switch view to plain text mode
A note: I put the "myHardCodedString" string just to test if the problem was caused by QString methods. Before I put that in, the error surfaced later on in the main function, but with it there, the error occurred right after the stated qDebug() line and before the next one.
I am using Qt 4.8.3 on Windows 7 x64 and VisualStudio 2010.
Hope that's enough information and thanks in advance.
Bookmarks