Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Upgraded Qt5.4.1 to 5.12.1, and now QCodec gives an exception



  • I've "inherited" a project which was working fine but we upgraded it to work with visual studio 2015 and qt 5.12.1.

    But for some reason it gives an exception now. What it basically does is it checks a location in regedit (which is written from another application) and reads a string value (which records the users). The query it does is :

    CMD:

    wmic /node:127.0.0.1 /user: "User" /password:"Password" class stdregprov call GetStringValue hDefKey="&H80000007" sSubKeyName=Software\Company\ApplicationServer sValueName=USERS"
    

    When I run this from cmd it returns a result and gives the same result in application too.

    The return value is
    OUT:

    Executing (stdregprov)->GetStringValue()
    
    Method execution successful.
    
    Out Parameters:
    instance of __PARAMETERS
    {
      ReturnValue = 0;
      sValue = "127.0.0.1-test.user";
    }
    

    But when it tries the codec in the code below, it gives an Access Violation Exception. Note that cmd is the parameters we sent to cmd (as shown above) and out is the response (as its shown above too).

    void MyUtil::runProcess(QString& cmd, QString& out, QString& arr){
    
    QProcess process;
    process.start(cmd);
    proces.waitForFinished(osProcessTimeout*1000);
    
    if(cmd.contains("sValueName=USERS")){ //which is true for our problem
    QByteArray arr = process.readAllStandardOutput();
    QTextCodec *codec = QTextCodec::codecForName("857");
    out = codec->toUnicode(arr);   // ----> WHERE IT GIVES THE EXCEPTION
    
    }else{
    
    out = process.readAllStandardOutput();
    
    }
    
    err = process.readAllStandardError();
    
    }
    


  • I used QTextCodec::codecForName("ISO-8859-9"); and it worked. Alternatively codecForLocale();


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    You can check the codec available with QTextCodec::availableCodecs.

    Note that it's always a good idea to check the returned pointer when dealing with that kind of methods.


Log in to reply