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. QProcess return string > qlistview?

QProcess return string > qlistview?

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.2k Views 1 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.
  • J Offline
    J Offline
    jocala
    wrote on last edited by
    #1

    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

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

      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

      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