Can't get QProcess::start() to work with QLineEdit's text()



  • I'm trying to make a front end for a program, and so I'm using QProcess, and specifically start(QString, QStringList). I managed to get output from:
    start("/bin/tar --help"), but when I try to specify a QStringList for arguments (specifically, reading a QLineEdit through QLineEdit->text()), I get total silence from the QProcess.

    Here's a bit of my code:
    @extraargs = new QLineEdit();
    extraargs->setPlaceholderText("extra arguments");
    QStringList testtwo;
    testtwo << extraargs->text();
    ...
    ..
    proc->start("/bin/ls", testtwo);
    @
    This returns silence. If testtwo were set using testtwo ="some string here" then it would work perfectly, but extraargs->text() doesn't seem to work. What am I doing wrong here?


  • Lifetime Qt Champion

    With the code you are showing, testtwo is empty.

    @extraargs->setPlaceholderText("extra arguments");@

    "extra arguments" being a place holder text, your QLineEdit content is empty


  • Moderators

    The string from your lineedit will be passed as one argument to /bin/ls. That gives rise to many interesting ways of failing:-)

    E.g. "-alF test" in your lineedit, will be passed to /bin/ls as one argument, not two.

    An empty string will also get passed as an empty argument. No idea what ls will do with any of those:)



  • Well yeah, the point is to have the user type something into QLineEdit, and then convert QLineEdit's contents into a QStringList somehow and pass it on to QProcess as an argument. Is there a better, more failproof way to do this?

    /bin/ls without any arguments should at least output something, so with start("/bin/ls", extraargs), it should output something even when extraargs is empty, or malformed.


Log in to reply
 

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