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. How to receive array from js?use QWebChannel
QtWS25 Last Chance

How to receive array from js?use QWebChannel

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 621 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.
  • my name is windM Offline
    my name is windM Offline
    my name is wind
    wrote on last edited by
    #1

    js:

    new QWebChannel(qt.webChannelTransport, function(channel) {
            // make dialog object accessible globally
            var js_object = channel.objects.jsObject;
            
            $("#save_data").click(function(){
                    var aa = new Array('name', 'c');
                    alert(JSON.stringify(aa));
                    js_object.receiveText(JSON.stringify(aa));
                }
                
            });
        });
    

    qt

    void PickerJsObject::receiveText(const QString &r_text)
    {
    
    
         qDebug()<<r_text;
    
    
    
         QJsonParseError error;
         QJsonDocument message = QJsonDocument::fromJson(messageData.toUtf8(), &error);
         if (error.error) {
             qWarning() << "Failed to parse text message as JSON object:" << messageData
                        << "Error is:" << error.errorString();
             return;
         } else if (!message.isObject()) {
             qWarning() << "Received JSON message that is not an object: " << messageData;
             return;
         }
    
     
    
    }
    

    console output:

    "[\"name\",\"c\"]"
    Received JSON message that is not an object:  "[\"name\",\"c\"]"
    

    JS how to return an array of data to QT? JS returns what format? QT and how to receive and parse, please enlighten.

    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