Qt Forum

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

    Update: Forum Guidelines & Code of Conduct

    When i used QProcess it returns warning: 'parent' may be used uninitialized in this function [-Wmaybe-uninitialized]

    General and Desktop
    5
    10
    1547
    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.
    • stackprogramer
      stackprogramer last edited by A Former User

      i want to uses QProcess in my app. according below link:
      i added too below requirements:

      Header:	#include <QProcess>
      qmake:	QT += core
      

      http://doc.qt.io/qt-5/qprocess.html

      my os is ubuntu and Qt5.7, too my project is console project.
      can any guide?
      thanks in advance

       QObject *socket;
          ...
          QString program = "./path/to/Qt/examples/widgets/analogclock";
          QStringList arguments;
          arguments << "-style" << "fusion";
      
          QProcess *myProcess = new QProcess(socket);
          myProcess->start(program, arguments);
      

      it returns this errors:

      /home/sp/Documents/socket/UDPSocketConsole/main.cpp:21: warning: 'socket' may be used uninitialized in this function [-Wmaybe-uninitialized]
           QProcess *myProcess=new QProcess(socketradar);
      
      
      
      jsulm 1 Reply Last reply Reply Quote 0
      • jsulm
        jsulm Lifetime Qt Champion @stackprogramer last edited by jsulm

        @stackprogramer In the code you pasted you did not initialize socket! It should point to an object which you want to use as parent.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        N 1 Reply Last reply Reply Quote 2
        • stackprogramer
          stackprogramer last edited by

          hi,yes i know it is warning. in my source instead parent is socket here is my typo.
          when i inserted qDebug() <<"part1" qDebug() <<"part2" qDebug() <<"part3"in my source:

          QObject *socket;
           qDebug() <<"part1" ;
              QString program = "./path/to/Qt/examples/widgets/analogclock";
              QStringList arguments;
              arguments << "-style" << "fusion";
          qDebug() <<"part2" ;
              QProcess *myProcess = new QProcess(socket);
          qDebug() <<"part3" ;
              myProcess->start(program, arguments);
          

          part 1 and 2 print in console but part 3 is can not print console. i want to use QProcess to communicate to a other c++ executable file.
          but QProcess doesn't work for me.
          thanks

          jsulm stackprogramer 2 Replies Last reply Reply Quote 0
          • jsulm
            jsulm Lifetime Qt Champion @stackprogramer last edited by

            @stackprogramer Your socket pointer is not initialized! You need to assign it a pointer to an existing object.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply Reply Quote 2
            • stackprogramer
              stackprogramer @stackprogramer last edited by stackprogramer

              Re: when i used QProcess it returns warning: 'parent' may be used uninitialized in this function [-Wmaybe-uninitialized]

              finally i change my method. i used this structure:
              i had a ddd exe file in ubuntu that when i execute it, it returns "Hello World!"
              ddd
              i used this source it works
              best regards stackprogramer

              #include <QCoreApplication>
              
              #include <myudp.h>
              #include <QProcess>
              #include <QObject>
              
              
              
              
              int main(int argc, char *argv[])
              {
                  QCoreApplication a(argc, argv);
                  qDebug()<<"hi";
              
              //    MyUDP test;
              //   test.HelloUDP();
              //   test.readyRead();
                 // QObject *socketradar;
              
                  QString program="/home/sp/Documents/socket/UDPSocketConsole/ddd";
                  QStringList arguments;
                  arguments<<"1";
                  qDebug()<<"hi2";
              
                  QProcess myProcess;
                  qDebug()<<"hi3";
              
              
                  myProcess.start(program,arguments);
              
                  //qDebug()<< myProcess<<"hi";
                myProcess.waitForFinished();
                qDebug()<<"hi4";
                QByteArray  output=myProcess.readAllStandardOutput();
                qDebug()<<output;
                 // return a.exec();
              }
              
              

              now we can see our out exe file

              alt text

              1 Reply Last reply Reply Quote 0
              • N
                nanor @jsulm last edited by

                @jsulm Could you please explain how to do that?
                Thank you

                JonB Pl45m4 2 Replies Last reply Reply Quote 0
                • JonB
                  JonB @nanor last edited by JonB

                  @nanor
                  How to do what "that"?

                  N 1 Reply Last reply Reply Quote 0
                  • Pl45m4
                    Pl45m4 @nanor last edited by Pl45m4

                    @nanor

                    This is very basic C++

                    Declaration

                    • QObject *socket;

                    Initialization could look like this:
                    (assigns an address to that pointer)

                    • socket = new QObject();

                    Otherwise socket is no valid parent for QProcess


                    If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                    ~E. W. Dijkstra

                    N 1 Reply Last reply Reply Quote 1
                    • N
                      nanor @JonB last edited by

                      @JonB The initialization. I set it to this and the code worked well. Thank you so much.

                      1 Reply Last reply Reply Quote 0
                      • N
                        nanor @Pl45m4 last edited by

                        @Pl45m4 Thank you so much. I set it to "This" and my code worked well.

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post