QProcess return string > qlistview?



  • The code below (using QProcess) does a find and returns the result in a qstring "command".

    @
    QProcess mprocess;
    mprocess.setProcessChannelMode(QProcess::MergedChannels);
    cstring = "adb shell su -c find /storage/usb/ -name update.zip" ;
    mprocess.start(cstring);
    mprocess.waitForFinished(-1);
    command=mprocess.readAll();
    @

    If the find has results QProcess seems to place them into the qstring with an eol after each item:

    @
    /storage/usb/sdf1/update.zip
    /storage/usb/sde1/update.zip
    /storage/usb/sdd1/update.zip
    /storage/usb/sdb1/update.zip
    @

    How can I break up this qstring and add each subitem to a qlistview? As expected the code below doesn't work. The listview looks like it has four items, but of course there's just one.

    @
    QListWidgetItem *newItem = new QListWidgetItem;
    newItem->setText(command);
    ui->listWidget->insertItem(0, newItem);
    @

    Edit: I tried:

    @
    QStringList list1 = command.split(endl);
    @

    @
    error: no matching member function for call to 'split'
    QStringList list1 = command.split(endl);
    @

    Which I don't get, it's a copy/paste from the docs:

    http://qt-project.org/doc/qt-5/qstring.html#split

                                  ~~~~~~~~^~~~~

  • Lifetime Qt Champion

    Hi,

    You can use "QString::split":http://qt-project.org/doc/qt-5/qstring.html#split to create a QStringList, create a QStringListModel for a QListView. Other wise use a loop to create all the items you need for a QListWidget.

    Hope it helps


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.