Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to call a constructor to get data from first window to second ...??



  • hello,
    im trying to get data from first window to second window ,but it happens when i self create button but if i do same by using designing im getting error in Display dp(ui->lineEdit->text()) line may be its about calling a function. can any one solve this bug ...??

    thanks
    @
    #include "popupwindow.h"
    #include "ui_popupwindow.h"
    #include <QPushButton>
    #include <QDebug>

    PopUpWindow::PopUpWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::PopUpWindow)
    {
    ui->setupUi(this);
    QPushButton *pb=new QPushButton(this);
    pb->setText("Click Me");
    pb->setGeometry(200,150,100,30);
    connect(pb,SIGNAL(clicked()),this,SLOT(pbClicked()));
    }

    void PopUpWindow::pbClicked()
    {
    qDebug() << "clicked";
    Display dp(ui->lineEdit->text());
    Display dp;
    dp.setModal(true);
    dp.exec();

    }

    PopUpWindow::~PopUpWindow()
    {
    delete ui;
    }

    void PopUpWindow::on_pushButton_clicked()
    {
    qDebug() << "clicked";
    Display dp(ui->lineEdit->text());------------------------------------------->//getting error in this line//
    //Display dp;
    dp.setModal(true);
    dp.exec();

    }

    #include "display.h"
    #include "ui_display.h"
    #include <QDebug>
    #include <QWidget>
    #include <time.h>
    #include <QTimer>
    Display::Display(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Display)
    {
    ui->setupUi(this);
    }
    Display::Display(QString text)
    {
    qDebug()<<"IN display constructer";

    ui->setupUi(this);
    
    ui->lineEdit->setText(text);
    qDebug()<<text;
    qDebug()<<"end of  display constructer";
    

    }
    Display::~Display()
    {
    delete ui;
    }
    @

    Edit: there are code tags. Please use them; Andre


  • Lifetime Qt Champion

    Hi,

    It's because you don't have a constructor that takes a QString parameter. If you look at QPushButton's documentation you'll see the various constructor available.


Log in to reply