Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Problems with [Q]GpgME and Qt6
Forum Update on Monday, May 27th 2025

Problems with [Q]GpgME and Qt6

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
9 Posts 3 Posters 943 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.
  • R Offline
    R Offline
    rjmx
    wrote on last edited by
    #1

    (Crossposting to gnupg-users mailing list)

    I have an app that works fine in Qt5. I use QGpgME to encrypt/decrypt messages and handle key usage. I'm trying to upgrade the app to Qt6, and, naturally, expected problems, but this one beats me.

    Here, for example, is the code I use to retrieve my secret key list:

    QGpgME::KeyListJob *job = QGpgME::openpgp()->keyListJob(false, false, false);
    
    // Prepare result vector
    std::vector<GpgME::Key> keys;
    
    // Execute it synchronously
    GpgME::KeyListResult result = job->exec(QStringList() <<
                                            QStringLiteral(""),  // No pattern: get all
                                            true, keys);        // Only secret keys
     delete job;
    

    Now, this is straight out of the "t-keylist.cpp" test file that comes with the GpgME source. It works perfectly well under Qt5. but under Qt6, it segfaults at the "job->exec" line.

    Anyone have a clue why it crashes under Qt6?

    Thanks,

    --
    Ron Murray rjmx@rjmx.net
    PGP Fingerprint: 4D99 70E3 2317 334B 141E 7B63 12F7 E865 B5E2 E761

    JonBJ 1 Reply Last reply
    0
    • R rjmx

      (Crossposting to gnupg-users mailing list)

      I have an app that works fine in Qt5. I use QGpgME to encrypt/decrypt messages and handle key usage. I'm trying to upgrade the app to Qt6, and, naturally, expected problems, but this one beats me.

      Here, for example, is the code I use to retrieve my secret key list:

      QGpgME::KeyListJob *job = QGpgME::openpgp()->keyListJob(false, false, false);
      
      // Prepare result vector
      std::vector<GpgME::Key> keys;
      
      // Execute it synchronously
      GpgME::KeyListResult result = job->exec(QStringList() <<
                                              QStringLiteral(""),  // No pattern: get all
                                              true, keys);        // Only secret keys
       delete job;
      

      Now, this is straight out of the "t-keylist.cpp" test file that comes with the GpgME source. It works perfectly well under Qt5. but under Qt6, it segfaults at the "job->exec" line.

      Anyone have a clue why it crashes under Qt6?

      Thanks,

      --
      Ron Murray rjmx@rjmx.net
      PGP Fingerprint: 4D99 70E3 2317 334B 141E 7B63 12F7 E865 B5E2 E761

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @rjmx said in Problems with [Q]GpgME and Qt6:

      it segfaults at the "job->exec" line.

      Where does your code verify the return result from job = QGpgME::openpgp()->keyListJob(false, false, false); for nullptr?
      Look at the stack trace in debugger when it segfaults. Are you saying it does on the job->exec(...) call or somewhere inside the exec() function?

      R 1 Reply Last reply
      0
      • JonBJ JonB

        @rjmx said in Problems with [Q]GpgME and Qt6:

        it segfaults at the "job->exec" line.

        Where does your code verify the return result from job = QGpgME::openpgp()->keyListJob(false, false, false); for nullptr?
        Look at the stack trace in debugger when it segfaults. Are you saying it does on the job->exec(...) call or somewhere inside the exec() function?

        R Offline
        R Offline
        rjmx
        wrote on last edited by
        #3

        @JonB Thanks for the reply.
        The code doesn't check for a nullptr reply to the keyListJob() call (although I agree that it should), but I'd checked (stepping through the code) that the result was non-zero. Checking now, it comes back with a value of "job @0x555555dbf5d0", which seems reasonable.

        I'd looked at the stack trace before, but it didn't seem to tell me much. This time, it gets

        1   QString::toUtf8_helper(QString const&)                                            0x7ffff5b63496 
        2   ??                                                                                0x7ffff7ef6325 
        3   ??                                                                                0x7ffff7eb9a60 
        4   ??                                                                                0x7ffff7eba58f 
        5   ??                                                                                0x7ffff7ebb67a 
        6   Cryptography::getKeyNames                               cryptography.cpp      53  0x55555557a082
        
        

        Cryptography::getKeyNames() is the function I wrote that contains the code in question. It crashed immediately upon executing the job->exec() call.

        Now I guess I need to figure out why it crashes on the QString::toUtf8_helper() call.

        .....Ron

        R 1 Reply Last reply
        0
        • R rjmx

          @JonB Thanks for the reply.
          The code doesn't check for a nullptr reply to the keyListJob() call (although I agree that it should), but I'd checked (stepping through the code) that the result was non-zero. Checking now, it comes back with a value of "job @0x555555dbf5d0", which seems reasonable.

          I'd looked at the stack trace before, but it didn't seem to tell me much. This time, it gets

          1   QString::toUtf8_helper(QString const&)                                            0x7ffff5b63496 
          2   ??                                                                                0x7ffff7ef6325 
          3   ??                                                                                0x7ffff7eb9a60 
          4   ??                                                                                0x7ffff7eba58f 
          5   ??                                                                                0x7ffff7ebb67a 
          6   Cryptography::getKeyNames                               cryptography.cpp      53  0x55555557a082
          
          

          Cryptography::getKeyNames() is the function I wrote that contains the code in question. It crashed immediately upon executing the job->exec() call.

          Now I guess I need to figure out why it crashes on the QString::toUtf8_helper() call.

          .....Ron

          R Offline
          R Offline
          rjmx
          wrote on last edited by
          #4

          @rjmx @JonB
          Further to this, this happens with all three occasions in this code, where I call QGpgME (finding secret keys, encryption and decryption), but the failing functions differ.

          Here's what happens with the decrypting function. The relevant code is

          // Create the job
             QGpgME::DecryptJob *decryptjob = QGpgME::openpgp()->decryptJob();
             // Execute it synchronously
             // decryptjob->exec: const QByteArray &cipherText, QByteArray &plainText
             GpgME::DecryptionResult decryptresult;
             decryptresult = decryptjob->exec(ciphertext, plaintext);
          

          and the stack trace becomes

          
          For the encryption task, the 
          1   QByteArray::operator=(QByteArray const&)                                          0x7ffff5b33540
          2   ??                                                                                0x7ffff7e9b10d
          3   Cryptography::decrypt                                      cryptography.cpp   203 0x55555557b1b2
          

          For the encryption task, the code is

          // encryptJob(/*ASCII Armor */false, /* Textmode */ false);
             // If 'recipient' is entry, GpgME does password encryption
             QGpgME::EncryptJob *encryptjob = QGpgME::openpgp()->encryptJob(true, true);
          
             QByteArray ciphertext, plaintext;
             plaintext = content.toUtf8();
             GpgME::EncryptionResult encryptresult = encryptjob->exec(recipient, plaintext, false, ciphertext);
          

          and the stack trace is

          1   QString::toUtf8_helper(QString const&)                                            0x7ffff5b63496
          2   ??                                                                                0x7ffff7ef6325
          3   ??                                                                                0x7ffff7eb9a60
          4   ??                                                                                0x7ffff7eba58f
          5   ??                                                                                0x7ffff7ebb67a
          6   Cryptography::encrypt                                      cryptography.cpp   125 0x55555557a86c
          

          Looks like there's a problem handling text, but not in the same function.

          R 1 Reply Last reply
          0
          • R rjmx

            @rjmx @JonB
            Further to this, this happens with all three occasions in this code, where I call QGpgME (finding secret keys, encryption and decryption), but the failing functions differ.

            Here's what happens with the decrypting function. The relevant code is

            // Create the job
               QGpgME::DecryptJob *decryptjob = QGpgME::openpgp()->decryptJob();
               // Execute it synchronously
               // decryptjob->exec: const QByteArray &cipherText, QByteArray &plainText
               GpgME::DecryptionResult decryptresult;
               decryptresult = decryptjob->exec(ciphertext, plaintext);
            

            and the stack trace becomes

            
            For the encryption task, the 
            1   QByteArray::operator=(QByteArray const&)                                          0x7ffff5b33540
            2   ??                                                                                0x7ffff7e9b10d
            3   Cryptography::decrypt                                      cryptography.cpp   203 0x55555557b1b2
            

            For the encryption task, the code is

            // encryptJob(/*ASCII Armor */false, /* Textmode */ false);
               // If 'recipient' is entry, GpgME does password encryption
               QGpgME::EncryptJob *encryptjob = QGpgME::openpgp()->encryptJob(true, true);
            
               QByteArray ciphertext, plaintext;
               plaintext = content.toUtf8();
               GpgME::EncryptionResult encryptresult = encryptjob->exec(recipient, plaintext, false, ciphertext);
            

            and the stack trace is

            1   QString::toUtf8_helper(QString const&)                                            0x7ffff5b63496
            2   ??                                                                                0x7ffff7ef6325
            3   ??                                                                                0x7ffff7eb9a60
            4   ??                                                                                0x7ffff7eba58f
            5   ??                                                                                0x7ffff7ebb67a
            6   Cryptography::encrypt                                      cryptography.cpp   125 0x55555557a86c
            

            Looks like there's a problem handling text, but not in the same function.

            R Offline
            R Offline
            rjmx
            wrote on last edited by
            #5

            @rjmx @JonB
            Just tried it again on the keyListJob function, got the same crash on the same function (QString::toUtf8_helper(QString const&)), but this time got into the disassemblercrash disassemble.png

            Christian EhrlicherC 1 Reply Last reply
            0
            • R rjmx

              @rjmx @JonB
              Just tried it again on the keyListJob function, got the same crash on the same function (QString::toUtf8_helper(QString const&)), but this time got into the disassemblercrash disassemble.png

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

              My guess is that you mix debug and release libraries which you should not do when using msvc.

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

              R 1 Reply Last reply
              0
              • Christian EhrlicherC Christian Ehrlicher

                My guess is that you mix debug and release libraries which you should not do when using msvc.

                R Offline
                R Offline
                rjmx
                wrote on last edited by
                #7

                @Christian-Ehrlicher Perhaps I should have said this earlier, but I’m doing this on Linux with gcc. All I can say is that I’ve changed nothing in the switch from Qt5 to Qt6 other than changing the kit (and fixing issues caused by a change in the calling arguments for QCalendarWidget::paintCell()).
                Tomorrow, I’ll delve into the source code for QGpgME and see if I can see anything obvious.

                Christian EhrlicherC 1 Reply Last reply
                0
                • R rjmx

                  @Christian-Ehrlicher Perhaps I should have said this earlier, but I’m doing this on Linux with gcc. All I can say is that I’ve changed nothing in the switch from Qt5 to Qt6 other than changing the kit (and fixing issues caused by a change in the calling arguments for QCalendarWidget::paintCell()).
                  Tomorrow, I’ll delve into the source code for QGpgME and see if I can see anything obvious.

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

                  Ok, then are you sure QGpgME is compiled and linked against Qt6? Check with ldd.

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

                  R 1 Reply Last reply
                  1
                  • Christian EhrlicherC Christian Ehrlicher

                    Ok, then are you sure QGpgME is compiled and linked against Qt6? Check with ldd.

                    R Offline
                    R Offline
                    rjmx
                    wrote on last edited by
                    #9

                    @Christian-Ehrlicher
                    Good point. I'd checked with the Debian maintainers of gpgme, and they replied they were Qt6-compatible (at least, that was my understanding). Taking your advice to try ldd, however, I get

                    ron:~/$ ldd /usr/lib/x86_64-linux-gnu/libqgpgme.so.15
                    ..
                    ..
                    ..
                    	libQt5Core.so.5 => /lib/x86_64-linux-gnu/libQt5Core.so.5 (0x00007f8bcf600000)
                    

                    So, Qt5Core but no mention of Qt6Core? That doesn't look good.

                    I'll look into rebuilding it myself, I think.

                    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