-1

I have a QT widget that is functioning as a GUI for an external Process I am running. I am manually setting the path for this executable in the code. I would like to allow for the user to specify the path to the executable, from the GUI. My idea was to have some line edit box where the user enters the path, and once the path was entered it saved the path into a variable called program_path. This way when I call the process using this variable, it allows the user to choose which executable to run. I have searched the Internet, as well as stack overflow, and I was not able to find something relevant enough to what I was doing to attempt a solution. I was hoping someone could point me in the right direction as to how to implement this. Any suggested QT class or widgets to use? Any help is appreciated, in advance.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Gage Haas
  • 51
  • 1
  • 2
  • 8
  • You already have the solution in your description, have you implemented it? Do you have any problems in the implementation? – eyllanesc Mar 07 '18 at 00:14
  • I was unsure if this solution was the best way to go about solving the problem. I was not sure if it was possible to save user input into a string variable from the GUI interface in QT – Gage Haas Mar 07 '18 at 00:19
  • First try it, I do not know what kind of magic response you want, your problem is simple, each task is not expensive so a better solution would not make a big difference in performance. – eyllanesc Mar 07 '18 at 00:21

2 Answers2

0

Your idea is not practical a GUI for an external Process ... I would like to allow for the user to specify the path to the executable. If you are using an application in this way, then you should expect troubles. because giving the user that much control on your program is not good ..

QProcess can be used to run external applications but you are expected to have control inside your code .. different executables run in different ways (some are command line, some are GUI ...etc) and take different inputs (some executables run without input or switches from user , some require command line parameters ...etc) and they are different with their outputs (some apps require permissions, they give results in different ways).

Second, users are usually interested in final results not remember many executables names and details of using it.

Practically, it might be more suitable therefore to offer uses a list of choices of requests each corresponds to an executable, while you hide the details of calling each process inside your code.

To do that you need for example a QComboBox that shows users what options they have, and based on user selection you run QProcess needed to complete the action.

After all, taking a string from QLineEdit or a QCombobox is straightforward:

QString action = QLinedit::text();
QString action = QComboBox::currentText();

You might also need to show another selection process based on initial user selection, that takes more input from user and finally construct your QProccess with all details given from user.

Mohammad Kanan
  • 4,452
  • 10
  • 23
  • 47
0

To allow a user to select a file or repository, I advise to use the QFileDialog class (http://doc.qt.io/qt-5/qfiledialog.html#details). It's very convenient.

Code should look like:

    QFileDialog *_DialogWindow = new QFileDialog(this); // Creates a dialog window.
    bool result = _DialogWindow->exec();   // Window opens. User select something in his file system. Instructions returns only once he's done.
    if( result ) {
        _exePath = _DialogWindow->selectedFiles().first() ; // Get the path that was selected
    }

You may have to set some flags on your QFileDialog object, to specify which kind of file should be selected (.exe in your case)

Andéol Evain
  • 507
  • 2
  • 12