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. crash at Qt5Cored!QString::operator=
Forum Update on Monday, May 27th 2025

crash at Qt5Cored!QString::operator=

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 4 Posters 787 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.
  • T Offline
    T Offline
    thamht4190
    wrote on last edited by thamht4190
    #1

    I have the code as below:

    bool CloudResponseParser::parseAuthorizeResultToAppAccess(
            const QJsonObject &response, Cortex::Model::AppAccess &appAccess)
    {
        appAccess.accessToken = response["access_token"].toString();
        appAccess.refreshToken = response["refresh_token"].toString();
    
        appAccess.expireTime = currentDateTime().addSecs(response["expires_in"].toInt());
        appAccess.applicationId = response["app_id"].toString();
        appAccess.applicationVersion = response["app_version"].toString();
    
        QJsonObject jsonLicenseAgreement = response["license_agreement"].toObject();
        if (!jsonLicenseAgreement.isEmpty()) {
            if (jsonLicenseAgreement.contains("accepted")) {
                appAccess.licenseAgreementAccepted = jsonLicenseAgreement["accepted"].toBool();
                appAccess.licenseUrl = jsonLicenseAgreement["license_url"].toString();
            }
        }
        appAccess.licenseId = response["license"].toObject()["license_id"].toString();
        appAccess.licenseBundle = response["license"].toObject()["current_bundle_id"].toString();
        return true;
    }
    

    Sometimes, or more exactly rarely, I got the crash with the stack trace:

    STACK_TEXT:  
    00000065`480fafb0 00007ff8`a56fef5d : 00000000`00000050 00000065`480fb0f0 0000021c`759d0101 00007ff8`a5c713b6 : Qt5Cored!std::swap<QTypedArrayData<unsigned short> * __ptr64,void>+0x18
    00000065`480faff0 00007ff8`a5700e10 : 00000000`00000050 00000065`480fb0f0 00000000`00000001 0000021c`750e7c00 : Qt5Cored!qSwap<QTypedArrayData<unsigned short> * __ptr64>+0x1d
    00000065`480fb020 00007ff6`b69325c3 : 00000000`00000050 00000065`480fb0f0 00000065`480fb078 00007ff8`00000000 : Qt5Cored!QString::operator=+0x20
    00000065`480fb050 00007ff6`b5e3bd36 : 00000065`484ffa48 00000065`480fb940 00000000`00000000 00007ff8`a57092ad : CortexService!Cortex::Cloud::CloudResponseParser::parseAuthorizeResultToAppAccess+0xa3
    00000065`480fb2f0 00007ff6`b5e33996 : 00000065`484ffa38 00000000`00000000 00000065`480fb940 
    

    I did every way to check response and appAccess params, they refers to a non-null object. I don't know in which cases, I will get crash at QString::operator=+. Any advice?

    Thanks a lot!

    aha_1980A 1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Are there multiple threads involved? Is this method called in by multiple threads? You can check is thread sanitizer will have any warnings about it.

      Do you use QStringBuilder? (either by include or by define DEFINES *= QT_USE_QSTRINGBUILDER)?

      (Z(:^

      T 1 Reply Last reply
      2
      • T thamht4190

        I have the code as below:

        bool CloudResponseParser::parseAuthorizeResultToAppAccess(
                const QJsonObject &response, Cortex::Model::AppAccess &appAccess)
        {
            appAccess.accessToken = response["access_token"].toString();
            appAccess.refreshToken = response["refresh_token"].toString();
        
            appAccess.expireTime = currentDateTime().addSecs(response["expires_in"].toInt());
            appAccess.applicationId = response["app_id"].toString();
            appAccess.applicationVersion = response["app_version"].toString();
        
            QJsonObject jsonLicenseAgreement = response["license_agreement"].toObject();
            if (!jsonLicenseAgreement.isEmpty()) {
                if (jsonLicenseAgreement.contains("accepted")) {
                    appAccess.licenseAgreementAccepted = jsonLicenseAgreement["accepted"].toBool();
                    appAccess.licenseUrl = jsonLicenseAgreement["license_url"].toString();
                }
            }
            appAccess.licenseId = response["license"].toObject()["license_id"].toString();
            appAccess.licenseBundle = response["license"].toObject()["current_bundle_id"].toString();
            return true;
        }
        

        Sometimes, or more exactly rarely, I got the crash with the stack trace:

        STACK_TEXT:  
        00000065`480fafb0 00007ff8`a56fef5d : 00000000`00000050 00000065`480fb0f0 0000021c`759d0101 00007ff8`a5c713b6 : Qt5Cored!std::swap<QTypedArrayData<unsigned short> * __ptr64,void>+0x18
        00000065`480faff0 00007ff8`a5700e10 : 00000000`00000050 00000065`480fb0f0 00000000`00000001 0000021c`750e7c00 : Qt5Cored!qSwap<QTypedArrayData<unsigned short> * __ptr64>+0x1d
        00000065`480fb020 00007ff6`b69325c3 : 00000000`00000050 00000065`480fb0f0 00000065`480fb078 00007ff8`00000000 : Qt5Cored!QString::operator=+0x20
        00000065`480fb050 00007ff6`b5e3bd36 : 00000065`484ffa48 00000065`480fb940 00000000`00000000 00007ff8`a57092ad : CortexService!Cortex::Cloud::CloudResponseParser::parseAuthorizeResultToAppAccess+0xa3
        00000065`480fb2f0 00007ff6`b5e33996 : 00000065`484ffa38 00000000`00000000 00000065`480fb940 
        

        I did every way to check response and appAccess params, they refers to a non-null object. I don't know in which cases, I will get crash at QString::operator=+. Any advice?

        Thanks a lot!

        aha_1980A Offline
        aha_1980A Offline
        aha_1980
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @thamht4190 said in crash at Qt5Cored!QString::operator=+:

        QString::operator=+

        If I read the stack trace correctly, it's QString::operator= and +0x20 is an address offset.

        I have no idea what causes the crash, though.

        Regards

        Qt has to stay free or it will die.

        T 1 Reply Last reply
        2
        • sierdzioS sierdzio

          Are there multiple threads involved? Is this method called in by multiple threads? You can check is thread sanitizer will have any warnings about it.

          Do you use QStringBuilder? (either by include or by define DEFINES *= QT_USE_QSTRINGBUILDER)?

          T Offline
          T Offline
          thamht4190
          wrote on last edited by
          #4

          Are there multiple threads involved? Is this method called in by multiple threads?

          @sierdzio My application is multi thread, so I was afraid too. However, I checked very carefully that response and appAccess are accessed by only one thread. CloudResponseParser::parseAuthorizeResultToAppAccess(response, appAccess) is called only on this thread.

          Do you use QStringBuilder? (either by include or by define DEFINES *= QT_USE_QSTRINGBUILDER)?

          No, I don't use it.

          1 Reply Last reply
          0
          • aha_1980A aha_1980

            @thamht4190 said in crash at Qt5Cored!QString::operator=+:

            QString::operator=+

            If I read the stack trace correctly, it's QString::operator= and +0x20 is an address offset.

            I have no idea what causes the crash, though.

            Regards

            T Offline
            T Offline
            thamht4190
            wrote on last edited by
            #5

            @aha_1980 Yes, you're right. I updated the title.

            1 Reply Last reply
            1
            • sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #6

              appAccess is passed by (non-const) reference. Does that object live in the same thread as CloudResponseParser?

              Sorry for asking about this gain, but since you have a code that only sometimes fails I'm pretty sure threads are to blame. We just need to find where and how.

              (Z(:^

              kshegunovK 1 Reply Last reply
              4
              • sierdzioS sierdzio

                appAccess is passed by (non-const) reference. Does that object live in the same thread as CloudResponseParser?

                Sorry for asking about this gain, but since you have a code that only sometimes fails I'm pretty sure threads are to blame. We just need to find where and how.

                kshegunovK Offline
                kshegunovK Offline
                kshegunov
                Moderators
                wrote on last edited by kshegunov
                #7

                Not necessarily (although rather likely), one can pass a dangling reference (e.g. a temporary object).

                @thamht4190, please also provide the line where you invoke that method and how the objects that are passed came to be and how they're destroyed.

                PS. Also please provide a full backtrace. This doesn't say where the call originated. Is this a static method called from main()?

                Read and abide by the Qt Code of Conduct

                1 Reply Last reply
                4
                • T Offline
                  T Offline
                  thamht4190
                  wrote on last edited by
                  #8

                  Thanks all. Finally I can find out why I have this crash. All of you are right about appAccess which has been null before passing into CloudResponseParser::parseAuthorizeResultToAppAccess function. I didn't know that before because I read the wrong stack trace.
                  Thanks again for all of your support.

                  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