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. can anybody explain why QStringList() used in below line ?
Forum Updated to NodeBB v4.3 + New Features

can anybody explain why QStringList() used in below line ?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 3 Posters 245 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.
  • Q Offline
    Q Offline
    Qt embedded developer
    wrote on last edited by
    #1

    i want to understand below statement

    qProcessSysCmd ->start("bash",QStringList() << "-c" << sCommand.toLatin1().data());

    what this statement do internally ?

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

      Apparently, start() requires a QStringList. Instead of creating it earlier, like so:

      QStringList args;
      args.append("-c");
      args.append(sCommand);
      

      the author has decided to create it in-place (good idea, btw, it allows the compiler to optimize it). The syntax is rather old, in post C++11 world we'd rather write it like this:

      qProcessSysCmd ->start("bash", { "-c", sCommand });
      

      EDIT Removed .toLatin1().data() as it is, indeed, a bad idea to do this.

      (Z(:^

      1 Reply Last reply
      6
      • Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @sierdzio said in can anybody explain why QStringList() used in below line ?:

        sCommand.toLatin1().data()

        btw: this is useless and even wrong when the command contains non-latin1 characters

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        4

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved