Advertisement
KukuRuzo

qca qt6 win

Mar 25th, 2024
824
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.29 KB | None | 0 0
  1.  
  2.  
  3. diff --git a/CMakeLists.txt b/CMakeLists.txt
  4. index df655fbf..8d2a5bbb 100644
  5. --- a/CMakeLists.txt
  6. +++ b/CMakeLists.txt
  7. @@ -52,7 +52,7 @@ set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules" )
  8.  if(BUILD_WITH_QT6)
  9.    set(QT_MAJOR_VERSION 6)
  10.    message(STATUS "Building Qt 6 version")
  11. -  find_package(Qt6 COMPONENTS Core Test Core5Compat REQUIRED)
  12. +  find_package(Qt6 COMPONENTS Core Test REQUIRED)#Core5Compat REQUIRED)
  13.  else()
  14.    set(QT_MAJOR_VERSION 5)
  15.    message(STATUS "Building Qt 5 version")
  16. diff --git a/QcaConfig.cmake.in b/QcaConfig.cmake.in
  17. index ce9a8ab2..3975ac3e 100644
  18. --- a/QcaConfig.cmake.in
  19. +++ b/QcaConfig.cmake.in
  20. @@ -3,9 +3,9 @@
  21.  include(CMakeFindDependencyMacro)
  22.  find_dependency(Qt@QT_MAJOR_VERSION@Core)
  23.  
  24. -if (@QT_MAJOR_VERSION@ EQUAL 6 AND NOT @BUILD_SHARED_LIBRARIES@)
  25. -    find_dependency(Qt@QT_MAJOR_VERSION@Core5Compat)
  26. -endif()
  27. +#if (@QT_MAJOR_VERSION@ EQUAL 6 AND NOT @BUILD_SHARED_LIBRARIES@)
  28. +#    find_dependency(Qt@QT_MAJOR_VERSION@Core5Compat)
  29. +#endif()
  30.  
  31.  if(NOT TARGET @QCA_LIB_NAME@)
  32.    include("${CMAKE_CURRENT_LIST_DIR}/@QCA_CONFIG_NAME_BASE@Targets.cmake")
  33. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
  34. index 03a03a33..a2bfa8f4 100644
  35. --- a/src/CMakeLists.txt
  36. +++ b/src/CMakeLists.txt
  37. @@ -126,7 +126,7 @@ SET( SOURCES ${SOURCES} ${botan_SOURCES})
  38.  add_library(${QCA_LIB_NAME} ${SOURCES}  ${public_HEADERS})
  39.  target_link_libraries(${QCA_LIB_NAME} PUBLIC Qt${QT_MAJOR_VERSION}::Core)
  40.  if(BUILD_WITH_QT6)
  41. -  target_link_libraries(${QCA_LIB_NAME} PRIVATE Qt6::Core5Compat)
  42. +  #target_link_libraries(${QCA_LIB_NAME} PRIVATE Qt6::Core5Compat)
  43.  endif()
  44.  
  45.  if(WIN32)
  46. diff --git a/src/support/qpipe.cpp b/src/support/qpipe.cpp
  47. index 122e96a8..e7efe140 100644
  48. --- a/src/support/qpipe.cpp
  49. +++ b/src/support/qpipe.cpp
  50. @@ -36,9 +36,14 @@
  51.  
  52.  #ifdef Q_OS_WIN
  53.  #include <QMutex>
  54. +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
  55.  #include <QTextCodec>
  56.  #include <QTextDecoder>
  57.  #include <QTextEncoder>
  58. +#else
  59. +# include <QStringEncoder>
  60. +# include <QStringDecoder>
  61. +#endif
  62.  #include <QThread>
  63.  #include <QWaitCondition>
  64.  #else
  65. @@ -298,7 +303,11 @@ static int pipe_read_avail_console(Q_PIPE_ID pipe)
  66.  }
  67.  
  68.  // pass dec to keep a long-running decoder, else 0
  69. +#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
  70.  static int pipe_read_console(Q_PIPE_ID pipe, ushort *data, int max, bool *eof, QTextDecoder *dec = 0)
  71. +#else
  72. +static int pipe_read_console(Q_PIPE_ID pipe, ushort *data, int max, bool *eof, QStringDecoder decoder)
  73. +#endif
  74.  {
  75.      int  n, size, count;
  76.      bool own_decoder;
  77. @@ -314,12 +323,21 @@ static int pipe_read_console(Q_PIPE_ID pipe, ushort *data, int max, bool *eof, Q
  78.      if (count == 0)
  79.          return 0;
  80.  
  81. +#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
  82.      if (dec) {
  83.          own_decoder = false;
  84.      } else {
  85.          dec         = 0;
  86.          own_decoder = true;
  87.      }
  88. +#else
  89. +    if(decoder.isValid()) {
  90. +        own_decoder = false;
  91. +    } else {
  92. +        decoder     = QStringDecoder(QStringDecoder::Utf8);
  93. +        own_decoder = true;
  94. +    }
  95. +#endif
  96.  
  97.      size = 0;
  98.      for (n = 0; n < count && size < max; ++n) {
  99. @@ -333,7 +351,9 @@ static int pipe_read_console(Q_PIPE_ID pipe, ushort *data, int max, bool *eof, Q
  100.          if (!ret) {
  101.              // if the first read is an error, then report error
  102.              if (n == 0) {
  103. +#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
  104.                  delete dec;
  105. +#endif
  106.                  return -1;
  107.              }
  108.              // if we have some data, don't count this as an error.
  109. @@ -346,7 +366,11 @@ static int pipe_read_console(Q_PIPE_ID pipe, ushort *data, int max, bool *eof, Q
  110.          if (use_uni)
  111.              substr = QChar(uni);
  112.          else
  113. +#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
  114.              substr = dec->toUnicode((const char *)&ansi, 1);
  115. +#else
  116. +            substr = decoder(QByteArrayView((const char *)&ansi, 1));
  117. +#endif
  118.  
  119.          for (int k = 0; k < substr.length() && size < max; ++k) {
  120.              QChar c = substr[k];
  121. @@ -360,7 +384,9 @@ static int pipe_read_console(Q_PIPE_ID pipe, ushort *data, int max, bool *eof, Q
  122.          }
  123.      }
  124.      if (own_decoder)
  125. +#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
  126.          delete dec;
  127. +#endif
  128.  
  129.      return size;
  130.  }
  131. @@ -886,7 +912,9 @@ public:
  132.      bool          atEnd, atError, forceNotify;
  133.      int           readAhead;
  134.      SafeTimer    *readTimer;
  135. +#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
  136.      QTextDecoder *dec;
  137. +#endif
  138.      bool          consoleMode;
  139.      QPipeWriter  *pipeWriter;
  140.      QPipeReader  *pipeReader;
  141. @@ -904,8 +932,10 @@ public:
  142.          readTimer  = 0;
  143.          pipeWriter = 0;
  144.          pipeReader = 0;
  145. +#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
  146.          dec        = 0;
  147.  #endif
  148. +#endif
  149.  #ifdef Q_OS_UNIX
  150.          sn_read  = nullptr;
  151.          sn_write = nullptr;
  152. @@ -930,8 +960,10 @@ public:
  153.          pipeWriter = 0;
  154.          delete pipeReader;
  155.          pipeReader = 0;
  156. +#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
  157.          delete dec;
  158.          dec         = 0;
  159. +#endif
  160.          consoleMode = false;
  161.  #endif
  162.  #ifdef Q_OS_UNIX
  163. @@ -972,11 +1004,12 @@ public:
  164.          if (type == QPipeDevice::Read) {
  165.  #ifdef Q_OS_WIN
  166.              // for windows, the blocking mode is chosen by the QPipeReader
  167. -
  168. +#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
  169.              // console might need a decoder
  170.              if (consoleMode) {
  171.                  dec = 0;
  172.              }
  173. +#endif
  174.  
  175.              // pipe reader
  176.  #ifdef USE_POLL
  177. @@ -1268,16 +1301,38 @@ int QPipeDevice::read(char *data, int maxsize)
  178.  #endif
  179.          ushort *dest = (ushort *)destbuf.data();
  180.  
  181. -        ret = pipe_read_console(d->pipe, dest, num, &done, d->dec);
  182. +        ret = pipe_read_console(d->pipe, dest, num, &done, QStringDecoder(QStringDecoder::Utf8));
  183.          if (ret != -1) {
  184.              // for security, encode one character at a time without
  185.              //   performing a QString conversion of the whole thing
  186. +#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
  187.              QTextCodec                *codec = QTextCodec::codecForMib(106);
  188.              QTextCodec::ConverterState cstate(QTextCodec::IgnoreHeader);
  189. +#else
  190. +            QStringEncoder  encoder(QStringEncoder::Utf8);
  191. +#endif
  192.              int                        at = 0;
  193.              for (int n = 0; n < ret; ++n) {
  194.                  QChar      c(dest[n]);
  195. +#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
  196.                  QByteArray out = codec->fromUnicode(&c, 1, &cstate);
  197. +#else
  198. +                if (c.isHighSurrogate()) {
  199. +                    continue;
  200. +                }
  201. +                QByteArray out;
  202. +                // looks ugly, but we don't keep strings in insecure containers
  203. +                if (c.isLowSurrogate()) {
  204. +                    if (!n) continue;  // ignore completely invaid surrogate
  205. +                    QChar chars[2] = {QChar{dest[n-1]}, QChar{dest[n]}};
  206. +                    if (!chars[0].isHighSurrogate()) continue;  // another invalid surrogate
  207. +                    QStringView view{chars, 2};
  208. +                    out += QByteArray(encoder(view));
  209. +                } else {
  210. +                    QStringView view(&c, 1);
  211. +                    out += QByteArray(encoder(view));
  212. +                }
  213. +#endif
  214.                  memcpy(data + offset + at, out.data(), out.size());
  215.                  at += out.size();
  216.              }
  217.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement