0

I work on Qt and I don't understand how to link QPushButton and QLineEdit. I did this for the QPushButton :

QHBoxLayout     accountlayout;
QLabel          accountlabel("AccountServer");
QLineEdit       accountlineedit;
QPushButton     accountbuttonselect("Select");
QPushButton     accountbuttonlaunch("Launch");
QPushButton     accountbuttonstop("Stop");
QString         accountfile;

accountlayout.addWidget(&accountlabel);
accountlayout.addWidget(&accountlineedit);
accountlayout.addWidget(&accountbuttonselect);
accountlayout.addWidget(&accountbuttonlaunch);
accountlayout.addWidget(&accountbuttonstop);
QObject::connect(&accountbuttonselect,
    &QPushButton::clicked,
    [&window, &accountfile] {
        accountfile = QFileDialog::getOpenFileName(
            window,
            QObject::tr("Sélectionner un exécutable ..."),
            "C:/", QObject::tr("Exécutable (*.exe)"));
    });
layout.addLayout(&accountlayout);

I open QFileDialog to search for an executable file and I want to set the QLineEdit to show the directory specified. How can I do that?

AAEM
  • 1,837
  • 2
  • 18
  • 26
Meugiwara
  • 599
  • 1
  • 7
  • 13
  • Does my edit explain what you meant to ask for? – iksemyonov Oct 16 '16 at 13:37
  • If that's the case, you need to create a `QFileDialog` yourself and use the `directory()` method instead of the convenience static method you're using right now. – iksemyonov Oct 16 '16 at 13:47
  • 1
    ... are you simply missing a call to `accountlineedit.setText(accountfile)`? – peppe Oct 16 '16 at 17:56
  • @peppe, I tried this but it doesn't work – Meugiwara Oct 16 '16 at 18:51
  • 1
    @Meugiwara , if what peppe suggested doesn't work, you need to provide more info, where do you have this snippet, is this in the main function? what happens exactly? how exactly doesn't it work? please try providing an [MCVE](https://stackoverflow.com/help/mcve). – Mike Oct 16 '16 at 20:24
  • I use it just under the QObject::connect for the &accountbuttonselect – Meugiwara Oct 16 '16 at 20:42
  • Please provide a *complete* `main.cpp` that reproduces the issue. See e.g. [here](http://stackoverflow.com/a/19011496/1329652) for inspiration. – Kuba hasn't forgotten Monica Oct 17 '16 at 14:07

0 Answers0