Get Value from a LineEdit in the MainWindow to be use in a dialog



  • Hi all:

    My problem is that I want to read the value of a LineEdit in the Main Windows and then use the value in a dialog.

    This should be the first step, in case that Line has a wrong Value or is Empty an error is thrown.

    Could I getthis value during the Slot and then pass to the dialog ?

    public:
    explicit AddVisit(QWidget *parent = 0, Qstring number);
    ~AddVisit();

    Please, could someone tell me how to pass the variable after click?

    void MainWindow::on_createDatePushButton_clicked()
    {
    QString number = ui->lineEditNumber->text();
    AddVisit myAddVisit;
    myAddVisit.setModal(true);
    myAddVisit.exec();
    }


  • Lifetime Qt Champion

    Hi,

    It depends on how you are going to use that dialog.



  • @SGaist The idea is have the QString Number as key in a table. Two different tables but with the same key.


  • Lifetime Qt Champion

    How are you using that dialog ?

    Are you showing it permanently ? On demand ? Are you re-creating it each time ? Can that value be changed while the dialog is shown ?


  • Qt Champions 2018

    @iyustlop Why not just pass it as parameter to the dialog constructor?

    void MainWindow::on_createDatePushButton_clicked()
    {
    QString number = ui->lineEditNumber->text();
    AddVisit myAddVisit(number);
    // myAddVisit.setModal(true); <-- This is not needed as exec() already shows the dialog as modal dialog
    myAddVisit.exec();
    }
    


  • @jsulm thank you for the idea. The problem is how i have to modify the construtor to include this parameter

    AddVisit::AddVisit(QWidget *parent, QString number) :
    QDialog(parent),
    ui(new Ui::AddVisit)
    {
    ui->setupUi(this);
    }

    This way, I have an error due to this constructor is not known.


  • Lifetime Qt Champion

    Did you also modify the declaration ?

    By the way, the common implementation is to have parent as last parameter.



  • The result that works:

    AddVisit::AddVisit(QString number, QWidget *parent, QString number) :
    QDialog(parent),
    ui(new Ui::AddVisit)
    {
    ui->setupUi(this);
    }

    With this costructor everything works.

    Thank you very much indeed for the help.


  • Lifetime Qt Champion

    Don't you have one number parameter too many ?


Log in to reply