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
    

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

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


  • 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!"
    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


Log in to reply
 

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