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::Write()::issue
Forum Updated to NodeBB v4.3 + New Features

QProcess::Write()::issue

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 5 Posters 1.5k Views 4 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.
  • QT_QT_QTQ Offline
    QT_QT_QTQ Offline
    QT_QT_QT
    wrote on last edited by QT_QT_QT
    #1

    Hey guys! I have a question here. There is a line edit box and push button in my program. Supposedly,the line edit box is let the let user to type text, and the program must be able to get the text from what the user had typed , and then perform a following function unto it . such function are show in below code.

    void MainWindow::on_pushButton_3_clicked()
    {
        QString message A= "mkdir ";
        QString messageB = ui->lineEdit->text();
        messageA.append(messageB);
    
    
        QProcess procB;
        procB.start("cmd");
        if(!procB.waitForStarted()){
            return;
        }
     
        procB.write(messageA);
        QByteArray outputB;
        if(procB.waitForReadyRead()){
            outputB += procB.readAll();
        }
       qDebug()<<outputB;
    
    }
    

    I keep getting this error when i try to compile the codes, the error lies at the "procB.write(messageA)". The further explanation of the error is cannot convert arguement 1 from QString to const char. i know this cannot be done according to the Documentation. If there is another alternative solution that more or less serving the same purpose as my function, then please share it with me. Your help will be appreciated !

    K 1 Reply Last reply
    0
    • QT_QT_QTQ QT_QT_QT

      Hey guys! I have a question here. There is a line edit box and push button in my program. Supposedly,the line edit box is let the let user to type text, and the program must be able to get the text from what the user had typed , and then perform a following function unto it . such function are show in below code.

      void MainWindow::on_pushButton_3_clicked()
      {
          QString message A= "mkdir ";
          QString messageB = ui->lineEdit->text();
          messageA.append(messageB);
      
      
          QProcess procB;
          procB.start("cmd");
          if(!procB.waitForStarted()){
              return;
          }
       
          procB.write(messageA);
          QByteArray outputB;
          if(procB.waitForReadyRead()){
              outputB += procB.readAll();
          }
         qDebug()<<outputB;
      
      }
      

      I keep getting this error when i try to compile the codes, the error lies at the "procB.write(messageA)". The further explanation of the error is cannot convert arguement 1 from QString to const char. i know this cannot be done according to the Documentation. If there is another alternative solution that more or less serving the same purpose as my function, then please share it with me. Your help will be appreciated !

      K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      @QT_QT_QT
      In your post it says:

          QString message A= "mkdir ";
      

      This hsould give already a compile error.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • QT_QT_QTQ Offline
        QT_QT_QTQ Offline
        QT_QT_QT
        wrote on last edited by
        #3

        HI

        its just a typo when i copy and paste the code. my apologies.

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          something like
          procB.write( messageA.toStdString().c_str() );

          kshegunovK 1 Reply Last reply
          1
          • mrjjM mrjj

            something like
            procB.write( messageA.toStdString().c_str() );

            kshegunovK Offline
            kshegunovK Offline
            kshegunov
            Moderators
            wrote on last edited by kshegunov
            #5

            @mrjj @QT_QT_QT
            Or possibly (which does seem simpler to me):

            static const char * const messageA = "mkdir";
            procB.write(messageA);
            

            If the QString is actually coming from another part of the program and is not a constant (as in your case), you can also use qPrintable:

            QString messageA("mkdir");
            procB.write(qPrintable(messageA));
            

            Read and abide by the Qt Code of Conduct

            1 Reply Last reply
            1
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi,

              You can also just use QByteArray.

              QByteArray messageA("mkdir");
              procB.write(messageA);
              

              and if it comes for whatever reason from a QString.

              QString messageA("mkdir");
              procB.write(messageA.toLatin1());
              

              Unless you are on a system that uses an encoding not matching Latin1. In that case you can replace toLatin1 with toUtf8.

              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
              0
              • QT_QT_QTQ Offline
                QT_QT_QTQ Offline
                QT_QT_QT
                wrote on last edited by
                #7

                Greetings to @mrjj & @kshegunov

                @mrjj said:

                procB.write( messageA.toStdString().c_str() );

                Thank you for providing solution over here. mrjj's solution works for me ! thank you very much!

                1 Reply Last reply
                0

                • Login

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