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

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

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


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

  • Moderators

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

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

  • Moderators

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

  • 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!"
    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);
    //    MyUDP test;
    //   test.HelloUDP();
    //   test.readyRead();
       // QObject *socketradar;
        QString program="/home/sp/Documents/socket/UDPSocketConsole/ddd";
        QStringList arguments;
        QProcess myProcess;
        //qDebug()<< myProcess<<"hi";
      QByteArray  output=myProcess.readAllStandardOutput();
       // return a.exec();

    now we can see our out exe file

    alt text

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.