Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Arabic encoding display problem in qt 4.8
Forum Updated to NodeBB v4.3 + New Features

Arabic encoding display problem in qt 4.8

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 2 Posters 617 Views
  • 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.
  • S Offline
    S Offline
    sidouo
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      2
      • S Offline
        S Offline
        sidouo
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @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/

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          2
          • S Offline
            S Offline
            sidouo
            wrote on last edited by
            #5

            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+"' );";
            

            }

            Christian EhrlicherC 1 Reply Last reply
            0
            • S Offline
              S Offline
              sidouo
              wrote on last edited by
              #6

              It works, great . thanks a lot

              1 Reply Last reply
              0
              • S sidouo

                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+"' );";
                

                }

                Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @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.

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                S 1 Reply Last reply
                2
                • Christian EhrlicherC Christian Ehrlicher

                  @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.

                  S Offline
                  S Offline
                  sidouo
                  wrote on last edited by
                  #8

                  @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

                  1 Reply Last reply
                  1

                  • Login

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