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

Arabic encoding display problem in qt 4.8



  • Hello Qt Community,

    i used to develop with Qt Framwork/mingw. recentry i faced a problem with arabic language. when writing typing in a QlineEdit a text in arabic and using getText() metho, the return QString is remplaced by question marque. i tried to display with qDebug() and it the same problem. i trie resolving the problem with all possibility combintion. my source file is utf8. how can i resolve this problem. thank you all.


  • Qt Champions 2019

    Did you actually try to display your returned text in a QLabel? Using qDebug() on windows will not really work since cmd.exe has problems with non-locale characters.
    Therefore use a QLabel or properly write the returned string into a file.



  • Hi, thanks for the reply.

    when displayed in QLabel it work but when displayed with qDebut().. it shows question mark. the problem is that the text returned from the QlineEdit is contactenated with a QString to create an insert sql query. when run, it insert the question marks instead of the text edited in the QlineEdit.


  • Qt Champions 2019

    @sidouo said in Arabic encoding display problem in qt 4.8:

    create an insert sql query. when run, it insert the question marks instead of the text edited in the QlineEdit.

    No, this won't happen - as I said above qDebug() is not a cirrect way to output something which doesn't fit to the current locale on windows.
    And putting a sql together by putting strings together which come from user input is for sure not the correct way - although it does work and it has nothing to do that qDebug() is showing question marks. You're looking for QSqlQuery::bindValue() - otherwise see https://xkcd.com/327/



  • Hi Christian,

    let me show you the query i have done in my code and tell me what is the best way to do it correctly.

    void DAjoutFamilleProduit::ajouterFamille()

    {

    unsigned char SFamilleProduitTable::addNewWithoutMessageDisplay()
    
    {
    
    
    
    
    
            QSqlQuery query;
    
            query.clear();
    
    
    
            QString requete;
    
            requete.clear();
    
    if(query.exec(requete))
    
            {
    
                   
                return (unsigned char) 0;
    
            }
    
            else {
    
    
    
                
    
                return (unsigned short) 1; //error
    
            }         
    
            requete = "insert  into famille_produit (code_famille, nom_famille) ";
    
            requete+="values ('"+m_code+"', '"+m_nom+"' );";
    

    }



  • It works, great . thanks a lot


  • Qt Champions 2019

    @sidouo said in Arabic encoding display problem in qt 4.8:

    tell me what is the best way to do it correctly.

    See https://doc.qt.io/qt-5/qsqlquery.html#approaches-to-binding-values on how to use bindValue(). As the comic already showed you, when someone enters "'); drop table famille_produit;" your table will be dropped due to sql injection.



  • @Christian-Ehrlicher

    You are right on the Sql injection. i used to do bind values in php codes but not in Qt. it all about the first time developpement habits.

    im very thankfull to you

    regards

    sidouo


Log in to reply