Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qprocess in thread
Forum Updated to NodeBB v4.3 + New Features

Qprocess in thread

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 3 Posters 764 Views 1 Watching
  • 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.
  • S Offline
    S Offline
    satyanarayana143
    wrote on last edited by
    #1

    In .h file

    QProcess *m_pRsyncprocess;

    In .cpp

    void FileReceiverThread::run()
    {
    // thread starts here
    qDebug() << " Thread started";

    socket = new QTcpSocket();
    
    // set the ID
    if(!socket->setSocketDescriptor(this->socketDescriptor))
    {
        // something's wrong, we just emit a signal
        emit error(socket->error());
        return;
    }
    
    // connect socket and signal
    // note - Qt::DirectConnection is used because it's multithreaded
    //        This makes the slot to be invoked immediately, when the signal is emitted.
    
    connect(socket, SIGNAL(readyRead()), this, SLOT(readyRead()), Qt::DirectConnection);
    connect(socket, SIGNAL(disconnected()), this, SLOT(disconnected()));
    
    // We'll have multiple clients, we want to know which is which
    qDebug() << socketDescriptor << " Client connected";
    
    
    m_pRsyncprocess = new QProcess();
    
    
    QObject::connect(m_pRsyncprocess, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(RsyncProcessfinished(int,QProcess::ExitStatus)));
    QObject::connect(m_pRsyncprocess, SIGNAL(started()), this, SLOT(RsyncProcessstarted()));
    
    // make this thread a loop,
    // thread will stay alive so that signal/slot to function properly
    // not dropped out in the middle when thread dies
    
    exec();
    

    }

    void FileReceiverThread::RsyncProcessfinished(int exitCode, QProcess::ExitStatus exitStatus)
    {
    qDebug() << "RsyncProcessFinished: " << exitCode << "exitStatus:" << exitStatus;

    QProcess *p = qobject_cast<QProcess*>(sender());
    
    qDebug() << "p->exitCode():" << p->exitCode() << "exitStatus:" << exitStatus;
    
    if(p->exitCode() == 0)
    {
        qDebug() << "########### File Received Sucessfully #################" /*<< sEdgeserverId << ip4String*/;
        socket->write("File Received Sucessfully");
    
        exec();
    }
    else if(p->exitCode() == 1 || p->exitCode() == 2)
    {
        qDebug() << "########### Syntax error (or) Protocol incompatibility #################" /*<< sEdgeserverId << cli_addr.toString()*/ ;
    }
    else if(p->exitCode() == 3)
    {
        qDebug() << "########### Errors selecting input/output files, dirs #################" /*<< sEdgeserverId << cli_addr.toString()*/ ;
    }
    else if(p->exitCode()== 23 || p->exitCode() == 24)
    {
        qDebug() << "########*/### Partial transfer due to error (or) Partial transfer due to vanished source files #################" /*<< sEdgeserverId << cli_addr.toString()*/ ;
    }
    

    }

    in this line QProcess p = qobject_cast<QProcess>(sender()); it is chrashing can anybody tell what is problem.any give me solution to solve.

    1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      And once again - makeing something complicated because of using a thread for no good reason...
      but anyway: since you already have a member m_pRsyncprocess - why do you need to do an qobject_cast<> there at all instead simply accessing the member?

      btw: Where do you clean up m_pRsyncprocess and socket ?

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      1
      • S Offline
        S Offline
        satyanarayana143
        wrote on last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • S Offline
          S Offline
          satyanarayana143
          wrote on last edited by
          #4

          m_pRsyncprocess running rsync commands that is not giving exact exitcode of rsync command.

          QProcess p = qobject_cast<QProcess>(sender());

          it is giving correct exit code of rsync

          Christian EhrlicherC 1 Reply Last reply
          0
          • S satyanarayana143

            m_pRsyncprocess running rsync commands that is not giving exact exitcode of rsync command.

            QProcess p = qobject_cast<QProcess>(sender());

            it is giving correct exit code of rsync

            Christian EhrlicherC Online
            Christian EhrlicherC Online
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @satyanarayana143 Then you're doing a lot of stuff wrong - m_pRsyncprocess and QProcess p = qobject_cast<QProcess>(sender()); must return the same pointer...
            And previously you told me that the qobject_cast<> was crashing, now you're telling me that the return code of the pointer retrieved by qobject_cast<> is different to what m_pRsyncprocess is returning... how can you know when the qobject_cast<> is crashing??

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            1 Reply Last reply
            2
            • S Offline
              S Offline
              satyanarayana143
              wrote on last edited by
              #6

              @satyanarayana143 said in Qprocess in thread:

              QProcess p = qobject_cast<QProcess>(sender());

              with out calling

              QProcess p = qobject_cast<QProcess>(sender());

              the exitcode is not of rsync exit code.

              if i call it is crashing

              QProcess p = qobject_cast<QProcess>(sender());

              1 Reply Last reply
              0
              • Christian EhrlicherC Online
                Christian EhrlicherC Online
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @satyanarayana143 said in Qprocess in thread:

                the exitcode is not of rsync exit code.

                How do you know?

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  satyanarayana143
                  wrote on last edited by
                  #8

                  if rsync command in terminal for error some exitcode is coming and for proper execution exitcode is different

                  but with Qporcess if error comes also exitcode is coming proper execution exitcode also same

                  JonBJ 1 Reply Last reply
                  0
                  • Christian EhrlicherC Online
                    Christian EhrlicherC Online
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    So did you actually check if you pass the same parameter on the command line and in your program?

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      satyanarayana143
                      wrote on last edited by
                      #10

                      yes i am giving same command in terminal and for Qprocess

                      Christian EhrlicherC 1 Reply Last reply
                      0
                      • S satyanarayana143

                        if rsync command in terminal for error some exitcode is coming and for proper execution exitcode is different

                        but with Qporcess if error comes also exitcode is coming proper execution exitcode also same

                        JonBJ Offline
                        JonBJ Offline
                        JonB
                        wrote on last edited by
                        #11

                        @satyanarayana143 said in Qprocess in thread:

                        if rsync command in terminal for error some exitcode is coming and for proper execution exitcode is different
                        but with Qporcess if error comes also exitcode is coming proper execution exitcode also same

                        No idea what this means? I don't believe you will see different behaviour in rsync depending on whether you run from terminal or via QProcess. Show running it from terminal and code for running it from Qt app.

                        1 Reply Last reply
                        0
                        • S satyanarayana143

                          yes i am giving same command in terminal and for Qprocess

                          Christian EhrlicherC Online
                          Christian EhrlicherC Online
                          Christian Ehrlicher
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          @satyanarayana143 said in Qprocess in thread:

                          yes i am giving same command in terminal and for Qprocess

                          I don't believe this - esp. since you did not post the code for it.

                          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                          Visit the Qt Academy at https://academy.qt.io/catalog

                          1 Reply Last reply
                          1

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved