Results 1 to 6 of 6

Thread: Release mode issue

  1. #1
    Join Date
    Apr 2013
    Posts
    14
    Thanks
    3
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Release mode issue

    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:

    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication a(argc, argv);
    4. MyWindow *mw= 0;
    5. QString s = QString("myHardCodedString").toLower().trimmed();
    6. qDebug() << s;
    7. if(a.argc() > 1)
    8. {
    9. qDebug() <<"before check";
    10. QString correctStr = MyHelper::getProgramStr();
    11. qDebug() <<"str: " << correctStr;
    12.  
    13. qDebug() << a.arguments();
    14. qDebug() << a.arguments().at(1);
    15.  
    16. QString res = a.arguments().at(1).toLower().trimmed();
    17. qDebug() << "arg: " << res;
    18.  
    19. //code below never reached in Release mode
    20. //..........
    21. }
    22. else
    23. {
    24. QErrorMessage *error = new QErrorMessage();
    25. //set errormessage
    26. //.........
    27. }
    28.  
    29. return a.exec();
    30. }
    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:
    Qt Code:
    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.

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Release mode issue

    Just clean build the application and make sure you are using correct version of release mode dlls when running in the release mode
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Apr 2013
    Posts
    14
    Thanks
    3
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Release mode issue

    Thanks for the response.

    However, I have tried clean building the solution and it is using the correct dlls (the correct Qt version and not the debug mode ones) but it still produces the same error.


    Added after 47 minutes:


    Additional information:

    I produced debug information for the release build and after running it, the error appears to happen at the QList<T>::free() function:

    Qt Code:
    1. // ### Qt 5: rename freeData() to avoid confusion with std::free()
    2. template <typename T>
    3. Q_OUTOFLINE_TEMPLATE void QList<T>::free(QListData::Data *data)
    4. {
    5. node_destruct(reinterpret_cast<Node *>(data->array + data->begin),
    6. reinterpret_cast<Node *>(data->array + data->end));
    7. qFree(data);
    8. }
    To copy to clipboard, switch view to plain text mode 

    Line 7 is where the debugger reports the exception. The QList is of type QList<QString> *const, it has more than 11 million elements and the free() function is called from this line in my own code:

    Qt Code:
    1. QString res = a.arguments().at(1).toLower().trimmed();
    To copy to clipboard, switch view to plain text mode 


    Added after 16 minutes:


    Another update:

    I have another project in the same solution that has the same problem (except the main window shows and the exception happens when a button is pressed) and after running its release mode build through the debugger I can see that the this pointer (for my QMainWIndow) is set to NULL in the button's SLOT. Again, this only happens in release mode.
    Last edited by regular; 25th April 2013 at 11:02.

  4. #4
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Release mode issue

    please show the output from this
    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication a(argc, argv);
    4. MyWindow *mw= 0;
    5. QString s = QString("myHardCodedString").toLower().trimmed();
    6. qDebug() << s;
    7. if(a.argc() > 1)
    8. {
    9. qDebug() <<"before check";
    10. QString correctStr = MyHelper::getProgramStr();
    11. qDebug() <<"str: " << correctStr;
    12.  
    13. qDebug() << a.arguments();
    14. qDebug() << a.arguments();
    15.  
    16. qDebug() << a.arguments().at(1);
    17. qDebug() << a.arguments().at(1);
    18. }
    19.  
    20. }
    To copy to clipboard, switch view to plain text mode 


    However, I have tried clean building the solution and it is using the correct dlls (the correct Qt version and not the debug mode ones) but it still produces the same error.
    please show some proof for this. the command line call for the compiler + linker should be sufficient.

    Do you have different versions of Qt installed?

    You needn't waste time debugging Qt code. what you are seeing is not a Qt bug.
    Last edited by amleto; 27th April 2013 at 12:58.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  5. #5
    Join Date
    Apr 2013
    Posts
    14
    Thanks
    3
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Release mode issue

    Hi,

    Sorry for the late reply. The problem was fixed when I turned the compiler optimization off in release mode. However, I still don't know where the issue is and would rather find it and fix it itself isntead of turning optimization off. I ran this code (slightly modified of yours, added the trimmed() function):
    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication a(argc, argv);
    4. MyWindow *mw= 0;
    5. QString s = QString("myHardCodedString").toLower().trimmed();
    6. qDebug() << s;
    7. if(a.argc() > 1)
    8. {
    9. qDebug() <<"before check";
    10. QString correctStr = MyHelper::getProgramStr();
    11. qDebug() <<"str: " << correctStr;
    12.  
    13. qDebug() << a.arguments();
    14. qDebug() << a.arguments();
    15.  
    16. qDebug() << a.arguments().at(1);
    17. qDebug() << a.arguments().at(1).trimmed();
    18. }
    19.  
    20. }
    To copy to clipboard, switch view to plain text mode 
    And here's the output (there is no error when I remove the trimmed() function):
    Qt Code:
    1. "myhardcodedstring"
    2. before check
    3. str: "5F7141C1DA10FA56A55810589CCD20F94E5B565B"
    4. ("C:\Users\andreyu\Documents\Visual Studio 2010\Projects\MyApp\Win32\Release\MyApp.exe", "020076EA5F473EC798FF4B6407DBE337B33084B1", "C:\Users\andreyu\Desktop\options.xml")
    5. ("C:\Users\andreyu\Documents\Visual Studio 2010\Projects\MyApp\Win32\Release\MyApp.exe", "020076EA5F473EC798FF4B6407DBE337B33084B1", "C:\Users\andreyu\Desktop\options.xml")
    6. "020076EA5F473EC798FF4B6407DBE337B33084B1"
    7. First-chance exception at 0x00000029 in MyApp.exe: 0xC0000005: Access violation.
    8. Unhandled exception at 0x770915de in MyApp.exe: 0xC0000005: Access violation.
    To copy to clipboard, switch view to plain text mode 

    This happens when I turn optimization on, when it's off it all works fine.

    Here's the command line options for compiler:
    Qt Code:
    1. /I".\GeneratedFiles" /I"." /I"C:\Qt\4.8.3\include" /I".\GeneratedFiles\Release" /I"C:\Qt\4.8.3\include\QtCore" /I"C:\Qt\4.8.3\include\QtGui" /I"C:\Qt\4.8.3\include\QtXml" /I"C:\Qt\kdsoap\include" /I"C:\Qt\4.8.3\include\QtXmlPatterns" /nologo /W1 /WX- /Ox /Oy- /D "UNICODE" /D "WIN32" /D "QT_LARGEFILE_SUPPORT" /D "QT_DLL" /D "QT_NO_DEBUG" /D "NDEBUG" /D "QT_CORE_LIB" /D "QT_GUI_LIB" /D "QT_XML_LIB" /D "QT_XMLPATTERNS_LIB" /Gm- /EHsc /MD /GS /fp:precise /Zc:wchar_t- /Zc:forScope /Fp"Release\MyApp.pch" /Fa"Release\" /Fo"Release\" /Fd"Release\vc100.pdb" /Gd /analyze- /errorReport:queue
    To copy to clipboard, switch view to plain text mode 
    and linker:
    Qt Code:
    1. /OUT:"C:\Users\andreyu\Documents\Visual Studio 2010\Projects\MyApp\Win32\Release\\MyApp.exe" /NOLOGO /LIBPATH:"C:\Qt\kdsoap\lib" /LIBPATH:"C:\Qt\4.8.3\lib" "qtmain.lib" "QtCore4.lib" "QtGui4.lib" "QtXml4.lib" "kdsoap1.lib" "QtXmlPatterns4.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /MANIFEST /ManifestFile:"Release\MyApp.exe.intermediate.manifest" /ALLOWISOLATION /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /PDB:"C:\Users\andreyu\Documents\Visual Studio 2010\Projects\MyApp\Win32\Release\MyApp.pdb" /SUBSYSTEM:WINDOWS /PGD:"C:\Users\andreyu\Documents\Visual Studio 2010\Projects\MyApp\Win32\Release\MyApp.pgd" /TLBID:1 /DYNAMICBASE /NXCOMPAT /MACHINE:X86 /ERRORREPORT:QUEUE
    To copy to clipboard, switch view to plain text mode 

    And yes, I have Qt 4.8.3 and Qt 4.8.2_x64 installed.
    Last edited by regular; 29th April 2013 at 11:46.

  6. #6
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Release mode issue

    I bet if you uninstall the x64 version and make sure all files are removed, then the problem will 'go away'.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

Similar Threads

  1. Replies: 1
    Last Post: 7th March 2012, 21:34
  2. Replies: 1
    Last Post: 2nd November 2009, 12:02
  3. Replies: 9
    Last Post: 15th April 2009, 06:23
  4. Replies: 8
    Last Post: 10th October 2007, 18:20
  5. Release mode issue
    By stevey in forum Qt Programming
    Replies: 2
    Last Post: 8th November 2006, 20:26

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.