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
QtWS25 Last Chance

Qt 6: Replacement for QTextCodec

Scheduled Pinned Locked Moved Unsolved General and Desktop
qt6core5compatqtextcodecquazip
4 Posts 3 Posters 9.0k 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 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
    • hskoglundH Offline
      hskoglundH Offline
      hskoglund
      wrote on 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
      4
      • hskoglundH hskoglund

        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 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
        • hskoglundH Offline
          hskoglundH Offline
          hskoglund
          wrote on 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