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. QString replace %U
Qt 6.11 is out! See what's new in the release blog

QString replace %U

Scheduled Pinned Locked Moved Solved General and Desktop
41 Posts 5 Posters 14.5k 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.
  • sonichyS sonichy

    @JonB @jsulm

    I found the reason: QProcess->setProgram(sExec), sExec can not contain space, if not will fail to start.
    Program and arguments must separated!

    sExec = sExec.left(sExec.indexOf(" "));
    connect(action, &QAction::triggered, [=](){
        QProcess *process = new QProcess;
        process->setWorkingDirectory(path);
        qDebug() << sExec;
        process->setProgram(sExec);
        process->setArguments(QStringList() << filepath);
        bool b = process->startDetached();
        qDebug() << b;
    });
    
    JonBJ Offline
    JonBJ Offline
    JonB
    wrote on last edited by JonB
    #41

    @sonichy said in QString replace %U:

    QProcess->setProgram(sExec), sExec can not contain space, if not will fail to start.

    Not true. Space in the path to or name of the executable is fine.

    Program and arguments must separated!

    Which is why I told you earlier

    That line is not a program/executable, is it? The first word is the executable and the second word is an argument

    And that is why I would like you to read what we write and act on it, not just do nothing about it.....

    Whole of your lambda body code with QProcess *process = new QProcess onward could be replaced with just one line:

    QProcess::startDetached(sExec, QStringList() << filepath, path);
    

    if you want to avoid the memory leak.

    1 Reply Last reply
    3

    • Login

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