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. Qt 6: Replacement for QTextCodec

Qt 6: Replacement for QTextCodec

Scheduled Pinned Locked Moved Unsolved General and Desktop
qt6core5compatqtextcodecquazip
4 Posts 3 Posters 9.1k 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.
  • B Offline
    B Offline
    Bamp
    wrote on 11 Apr 2022, 17:23 last edited by
    #1

    Hello,
    for my application I need Quazip which need QTextCodec in several files. Currently, I use core5compat module but I want a clear Qt 6 application. Is there any replacement for QTextCodec class in Qt 6 (except core5compat)?

    Thank you for your answers!

    1 Reply Last reply
    0
    • H Offline
      H Offline
      hskoglund
      wrote on 11 Apr 2022, 17:37 last edited by
      #2

      Hi, yes I had a similar issue when upgrading to Qt6, I changed to using QStringConverter
      Because I sometimes I to build for Qt 5.15.2 my code looks like this example:

      ...
      // set the text encoding for the stream
      #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
          ts.setCodec(bUtf8 ? "UTF-8" : "ISO 8859-1");
      #else
          ts.setEncoding(bUtf8 ? QStringConverter::Utf8 : QStringConverter::Latin1);
      #endif
      ...
      
      C 1 Reply Last reply 11 Nov 2022, 15:22
      4
      • H hskoglund
        11 Apr 2022, 17:37

        Hi, yes I had a similar issue when upgrading to Qt6, I changed to using QStringConverter
        Because I sometimes I to build for Qt 5.15.2 my code looks like this example:

        ...
        // set the text encoding for the stream
        #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
            ts.setCodec(bUtf8 ? "UTF-8" : "ISO 8859-1");
        #else
            ts.setEncoding(bUtf8 ? QStringConverter::Utf8 : QStringConverter::Latin1);
        #endif
        ...
        
        C Offline
        C Offline
        CristianoPettinello
        wrote on 11 Nov 2022, 15:22 last edited by
        #3

        @hskoglund
        Could you please explain better how to use the QTextStream instead the QTextCodec?
        I am also porting the QuaZip using only the Qt 6 application (without the core5compat).
        Thank you for your answers!

        1 Reply Last reply
        0
        • H Offline
          H Offline
          hskoglund
          wrote on 11 Nov 2022, 23:28 last edited by
          #4

          You mean how to replace QTextCodec with QStringConverter? (QTextStream remains the same in Qt6 as in Qt5)
          I've only used QStringConverter for the case shown above but there are more info for example here

          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