Important: Please read the Qt Code of Conduct -


  • 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();
        QProcess procB;
        QByteArray outputB;
            outputB += procB.readAll();

    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 !

  • @QT_QT_QT
    In your post it says:

        QString message A= "mkdir ";

    This hsould give already a compile error.

  • HI

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

  • Lifetime Qt Champion

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

  • Moderators

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

    static const char * const messageA = "mkdir";

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

  • Lifetime Qt Champion


    You can also just use QByteArray.

    QByteArray messageA("mkdir");

    and if it comes for whatever reason from a QString.

    QString messageA("mkdir");

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

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

Log in to reply