Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved Qprocess not taking proper arguments

    General and Desktop
    qprocess qt creator qtcore
    4
    10
    1844
    Loading More Posts
    • 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.
    • Qjay
      Qjay last edited by Qjay

      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->setProcessChannelMode(QProcess::ForwardedChannels);
          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"}]

      JonB 1 Reply Last reply Reply Quote 0
      • JonB
        JonB @Qjay last edited by JonB

        @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....

        1 Reply Last reply Reply Quote 0
        • Qjay
          Qjay last edited by

          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 ??

          Pablo J. Rogina 1 Reply Last reply Reply Quote 0
          • Pablo J. Rogina
            Pablo J. Rogina @Qjay last edited by

            @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.

            Upvote the answer(s) that helped you solve the issue
            Use "Topic Tools" button to mark your post as Solved
            Add screenshots via postimage.org
            Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

            1 Reply Last reply Reply Quote 1
            • Qjay
              Qjay last edited by

              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"}]"

              1 Reply Last reply Reply Quote 0
              • SGaist
                SGaist Lifetime Qt Champion last edited by

                Hi,

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

                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 Reply Quote 1
                • Qjay
                  Qjay last edited by

                  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 :)

                  JonB 1 Reply Last reply Reply Quote 2
                  • JonB
                    JonB @Qjay last edited by JonB

                    @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.

                    1 Reply Last reply Reply Quote 2
                    • Qjay
                      Qjay last edited by

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

                      1 Reply Last reply Reply Quote 0
                      • SGaist
                        SGaist Lifetime Qt Champion last edited by

                        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.

                        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 Reply Quote 0
                        • First post
                          Last post