From 10:00 CET Friday 22nd November we will adjust how the server works to deal with some recently reported problems. Therefore there may be a load problem, if you experience more problems than usual trying to access the forum then please PM AndyS or any of the moderators so they can inform me.

Qprocess not taking proper arguments

  • hey i am trying to call a process from Qprocess but it's not taking args properly .

    below is the code

    #include <QCoreApplication>
    #include <QProcess>
    #include <QDebug>
    #include <QObject>
    int main(int argc, char *argv[])
        QCoreApplication a(argc, argv);
        QObject *parent = nullptr;
        QProcess *process = new QProcess(parent);
        const QString program  = "meson";
        const QStringList args = {"introspect", "--targets", "/home/nightmare/practice/meson/builddir/"};
        process->start(program, args);
        return a.exec();
    OUTPUT of above code : 

    usage: meson [-h] [--prefix PREFIX] [--libdir LIBDIR]
    [--libexecdir LIBEXECDIR] [--bindir BINDIR] [--sbindir SBINDIR]
    [--includedir INCLUDEDIR] [--datadir DATADIR] [--mandir MANDIR]
    [--infodir INFODIR] [--localedir LOCALEDIR]
    [--sysconfdir SYSCONFDIR] [--localstatedir LOCALSTATEDIR]
    [--sharedstatedir SHAREDSTATEDIR]
    [--backend {ninja,vs,vs2010,vs2015,vs2017,xcode}]
    [--buildtype {plain,debug,debugoptimized,release,minsize}]
    [--strip] [--unity {on,off,subprojects}] [--werror]
    [--layout {mirror,flat}] [--default-library {shared,static}]
    [--warnlevel {1,2,3}] [--stdsplit] [--errorlogs]
    [--cross-file CROSS_FILE] [-D PROJECTOPTIONS] [-v]
    [--wrap-mode {WrapMode.default,WrapMode.nofallback,WrapMode.nodownload}]
    [directories [directories ...]]
    meson: error: unrecognized arguments: --targets /home/nightmare/practice/meson/builddir/


    but when i try it from terminal same commands the output is right

    meson introspect --targets /home/nightmare/practice/meson/builddir/ [{"build_by_default": true, "name": "myexe", "filename": "myexe", "id": "myexe@exe", "installed": false, "type": "executable"}]

  • @Qjay
    Although one has to respect the output you show from typing at the terminal, from the meson usage message I have to say I can see neither introspect nor --targets arguments, which seems pretty odd.... ?

    [If introspect is one of the directories, I still don't see the --targets after that in the usage...]

    If you perhaps practised with some other command & arguments (e.g. ls), you might satisfy that QProcess does indeed pass arguments correctly....

  • introspect is not a directory . introspect is a a argument / parameter that meson takes ( mentioned in official docs of meson too )

    have you tried it on your meson project ??

  • @Qjay just in case, the meson output you posted didn't include --targets and the QStringList args shown above didn't include the JSON parameter you shown in the command line example.

  • this was the command i passed in terminal : "meson introspect --targets /home/nightmare/practice/meson/builddir/"

    and this was the output : "[{"build_by_default": true, "name": "myexe", "filename": "myexe", "id": "myexe@exe", "installed": false, "type": "executable"}]"

  • Lifetime Qt Champion


    Do you have several versions of meson installed ?
    Do you have maybe a modified PATH environment variable in your command prompt ?

  • found it . It was my fault . i was calling meson directly whereas meson is installed in "/usr/local/bin/meson"

    terminal does the path expansion but qprocess does not .

    so i changed it to const QString program = "/usr/local/bin/meson";

    works fine now :)

  • @Qjay

    terminal does the path expansion but qprocess does not

    For the record, that is not true. Unless your shell has an "alias" for meson, which I doubt.

    More likely they have different PATH environment variables. Which does not explain why you say you received message meson: error: unrecognized arguments, which would not happen if meson (of some kind) was not on your PATH. You may like to investigate why that is, up to you.

  • hmm you are right too . Not sure why it happened though.

  • Lifetime Qt Champion

    You might have modified PATH in your terminal session only for example.

    Or you may have modified PATH in the Run part of the Project panel.