Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. qt-qml-Qt Creator use msvc2017 qDebug print text messy on windows7
QtWS25 Last Chance

qt-qml-Qt Creator use msvc2017 qDebug print text messy on windows7

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 338 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.
  • M Offline
    M Offline
    make2
    wrote on last edited by make2
    #1

    I use MSVC 2017

    set env encoding utf-8: https://i.stack.imgur.com/BK70l.png

    set text eidtor encoding utf-8: https://i.stack.imgur.com/6sYw6.png

    I add #pragma execution_character_set("utf-8") to cpp file then

    cout<< "六六六" <<endl;
    qDebug() << "qu: 六六六";
    // output:
    // 六六六
    // qu: ������
    

    Update1: fromUtf8

    I remove #pragma execution_character_set("utf-8") and add this to .pro file

    msvc {
        QMAKE_CFLAGS += /utf-8
        QMAKE_CXXFLAGS += /utf-8
    }
    

    then run:

    cout<< "六六六" <<endl;
    qDebug() << QString::fromUtf8("qu: 六六六");
    // output:
    // 六六六
    // "qu: ������"
    

    The question remains

    Update2: QStringLiteral

    cout<< "六六六" <<endl;
    qDebug() << QStringLiteral("qu: 六六六");
    // output:
    // 六六六
    // "qu: ��\uE15E����?"
    

    Update3: waring this

    d167db56-c182-4213-994d-0a6f2d7aeb24-image.png

    Update 4:

    I save with UTF-8
    c17ef3ef-a7b2-4cd0-9802-416f1ecad129-image.png

    Update5: qUtf8Printable

    cout<< "六六六" <<endl;
    qDebug() << qUtf8Printable("qu: 六六六");
    // output:
    // 六六六
    // qu: ������
    

    thanks, but not work

    Update6:

    I want to use WebEngineView in MSVC, so I use UTF-8

    Update7: toUnicode

    QTextCodec* codecUtf8 = QTextCodec::codecForName("UTF-8");
    cout<< "六六六" <<endl;
    qDebug() << codecUtf8->toUnicode("qu: 六六六");
    //output:
    //六六六
    //"qu: ������"
    

    Update8:

    I change env encoding to system, then it works, cout can not print text to console in Visual Studio

    qDebug() << "qu: 六六六";
    // output:
    // qu: 六六六
    
    KroMignonK 1 Reply Last reply
    0
    • M make2

      I use MSVC 2017

      set env encoding utf-8: https://i.stack.imgur.com/BK70l.png

      set text eidtor encoding utf-8: https://i.stack.imgur.com/6sYw6.png

      I add #pragma execution_character_set("utf-8") to cpp file then

      cout<< "六六六" <<endl;
      qDebug() << "qu: 六六六";
      // output:
      // 六六六
      // qu: ������
      

      Update1: fromUtf8

      I remove #pragma execution_character_set("utf-8") and add this to .pro file

      msvc {
          QMAKE_CFLAGS += /utf-8
          QMAKE_CXXFLAGS += /utf-8
      }
      

      then run:

      cout<< "六六六" <<endl;
      qDebug() << QString::fromUtf8("qu: 六六六");
      // output:
      // 六六六
      // "qu: ������"
      

      The question remains

      Update2: QStringLiteral

      cout<< "六六六" <<endl;
      qDebug() << QStringLiteral("qu: 六六六");
      // output:
      // 六六六
      // "qu: ��\uE15E����?"
      

      Update3: waring this

      d167db56-c182-4213-994d-0a6f2d7aeb24-image.png

      Update 4:

      I save with UTF-8
      c17ef3ef-a7b2-4cd0-9802-416f1ecad129-image.png

      Update5: qUtf8Printable

      cout<< "六六六" <<endl;
      qDebug() << qUtf8Printable("qu: 六六六");
      // output:
      // 六六六
      // qu: ������
      

      thanks, but not work

      Update6:

      I want to use WebEngineView in MSVC, so I use UTF-8

      Update7: toUnicode

      QTextCodec* codecUtf8 = QTextCodec::codecForName("UTF-8");
      cout<< "六六六" <<endl;
      qDebug() << codecUtf8->toUnicode("qu: 六六六");
      //output:
      //六六六
      //"qu: ������"
      

      Update8:

      I change env encoding to system, then it works, cout can not print text to console in Visual Studio

      qDebug() << "qu: 六六六";
      // output:
      // qu: 六六六
      
      KroMignonK Offline
      KroMignonK Offline
      KroMignon
      wrote on last edited by KroMignon
      #2

      @make2 Did you store you source code file as UTF-8 ?

      qDebug() << qUtf8Printable("qu: 六六六"); should do the job.

      EDIT:

      You can also setup codec for C-Strings:

       QTextCodec *codec = QTextCodec::codecForName("UTF-8");
       QTextCodec::setCodecForCStrings(codec);
      
      qDebug() << "qu: 六六六";
      

      ==> Sorry is not working/supported with Qt5

      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

      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 Extensions
      • Unsolved