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 after QJsonArray toVariantList() ...
Forum Updated to NodeBB v4.3 + New Features

crash after QJsonArray toVariantList() ...

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 1.8k Views 2 Watching
  • 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
    ttuna
    wrote on last edited by ttuna
    #1

    Hi,
    my application crashed with following implementation:

    template<class T> void Vector<T>::Read(const QJsonObject& io_json)
    {
        //Read values
        QJsonArray json_array = io_json[s_JSON_DATA_VALUE].toArray();
        QVariantList variant_list;
    
       //Qt Bug?
       variant_list = json_array.toVariantList();  //not working (implicit sharing / move semantics problem???)       
       //Qt Bug?
    }
    

    If i discard toVariantList() and use a for loop to copy all values from json_array to variant_list everything works fine. Please, could someone help me with that?

    Best regards,

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      A bit more information is needed to test that. What do you put in io_json ? How do you generate it ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • T Offline
        T Offline
        ttuna
        wrote on last edited by
        #3

        Unfortunately it's a project of a colleague but as far as i know the OJsonObject passed to the function is retrieved from a file using QJsonDocument object() method.

        The file looks similar to this:

        {
            "min" : -100,
            "max" : 100,
            "val" : [
                45,2,
                34,9,
                17,6
            ]
        }
        
        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Can you show how you are calling that function ?

          Can't reproduce your problem from your code and sample data.

          What version of Qt are you running ? On what OS ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • Hamed.MasafiH Offline
            Hamed.MasafiH Offline
            Hamed.Masafi
            wrote on last edited by
            #5

            @ttuna said:

            variant_list = json_array.toVariantList();

            Try this:

            variant_list = json_array.toVariantList(QVariantList());
            

            if worked then your json is invalid

            Remote object sharing (OO RPC)
            http://forum.qt.io/topic/60680/remote-object-sharing-oo-rpc-solved

            Advanced, Powerful and easy to use ORM for Qt5
            https://forum.qt.io/topic/67417/advanced-powerful-and-easy-to-use-orm-for-qt5

            1 Reply Last reply
            0
            • T Offline
              T Offline
              ttuna
              wrote on last edited by
              #6

              @Hamed-Masafi
              The variant_list is valid after creation. The problem occurs when the Read() function is going to be left.
              It seems that a stack object (i tip json_array) will be deleted and produces a crash.

              @SGaist
              Here are the lines which are calling the Read() function: (i have removed some validity checks)

              QFile load_file(load_path);
              QByteArray load_data = load_file.readAll();
              QJsonDocument load_doc(in_format == Json ? QJsonDocument::fromJson(load_data) : QJsonDocument::fromBinaryData(load_data));
              Read(load_doc.object());
              
              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Can you create minimal compilable example that reproduces the crash ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                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