Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [CLOSED]QTextCodecs causing application crash!! need help.
Qt 6.12 LTS is out! See what's new in the release blog

[CLOSED]QTextCodecs causing application crash!! need help.

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • musimbateM Offline
    musimbateM Offline
    musimbate
    wrote on last edited by
    #1

    Hi all,
    I have a problem with my application crashing probably due to text encodings transformations but i can't figure it out.I want the application to run normally when before march 2014 and display an expiry message after the date in a QMessageBox.When i comment out the code in the else clause the program exits normally but it crashes whenever that code is executed.I suspect that it is related to text encoding transformations.Any help will be appreciated.
    .Here is the code and thanks for your time:
    @int main(int argc, char *argv[])
    {

    // Uncomment next section to have memory leaks information
    // tracing in VC++ debug mode under Windows
    

    /*
    #if defined(_MSC_VER) && defined(_DEBUG)
    _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
    #endif
    */

    Q_INIT_RESOURCE(sankore);
    
    qInstallMsgHandler(ub_message_output);
    

    #if defined(Q_WS_X11)
    qDebug() << "Setting GraphicsSystem to raster";
    QApplication::setGraphicsSystem("raster");
    #endif

    UBApplication app("Sankore", argc, argv&#41;;
    
    
    //WE RETRIEVE THE CURRENT DATE AND SET THE EXPIRY DATE FOR
    //THE APPLICATION.
    
    QDate currentDate=QDate::currentDate(&#41;;
    QDate expiryDate= QDate(2014,3,31);
    
    
    
    //BUGFIX:
    //when importing a sankore file that contains a non standard character
    //the codecForLocale or the codecForCString is used to convert the file path
    //into a const char*. This is why in french windows setup the codec name shouldn't be
    //set to UTF-8. For example, setting UTF-8, will convert "Haïti" into "HaÂ-ti.
    
    QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
    //QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
    QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
    
    QStringList args = app.arguments();
    
    QString dumpPath = UBSettings::userDataDirectory() + "/log";
    QDir logDir(dumpPath);
    if (!logDir.exists())
        logDir.mkdir(dumpPath);
    
    .......................................
    

    //---->>>THE CODE RELEVANT TO THE PROBLEM IS DOWN HERE<<<<<-----

    //int result = app.exec&#40;fileToOpen&#41;;
    int result;
    
    if(currentDate.operator <=(expiryDate&#41;&#41;
    {
       result = app.exec&#40;fileToOpen&#41;;
    }
    
    else
    {
     QMessageBox mMessageBox;
     mMessageBox.setText("Your version of the program has expired!"&#41;;
     mMessageBox.exec(&#41;;
    
    result = 0;
    }
    
    app.cleanup(&#41;;
    
    qDebug(&#41; << "application is quitting";
    
    
    
    return result;
    

    }@

    Why join the navy if you can be a pirate?-Steve Jobs

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You need to give more information i.e os (seems to be windows), Qt version, compiler (seems to be VS but what version ?) etc...

      What does a run through the debugger tells you ?

      Also, this code is not even compilable so nobody can try it on its system.

      Removing all uncompilable pieces and using a QApplication, I don't have any problem with it on OS X.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • musimbateM Offline
        musimbateM Offline
        musimbate
        wrote on last edited by
        #3

        Thans SGaist for the reply,

        I am using Qt 4.8.1 ,Qt Creator 2.4.1 and visual studio’s 2008 compiler.my system is windows 7 .I have been able to successfuly build the application and I just need to tweak the main function to add some behaviour to the program to meet our needs.I have been doing this to no avail so far."Here is the current state of the problem":http://qt-project.org/forums/viewthread/27700/
        and I consider this thread closed since it is no more relevant .Sorry for my poor understanding.

        Why join the navy if you can be a pirate?-Steve Jobs

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt
        • Unsolved