Qt send pointer to window as reference to not create another window



  • Hi there,
    I got a problem with data and windows. I got one window (let's call him A)with QTableWidget component and another(let's call him B) with few QLineEdit's to get data from user. When user press button I want send the data to A window and update table with data. I got problem qDebug() in A window shows the sent data corecttly but table is not update. I heard that the problem is in the B window(where user fills QLineEdit's with data) because I make another window A instead of using the created one. I heard that I should send pointer to A window as a reference in B window constructor . Can someone show me how I can do this?



  • to get pointer of window A use this. When calling window B in constructor write(this).
    Then in window B you can do what you want with this pointer to window A.



  • Mayby try using Qt's signal slot system:

    //A->reciver
    //B->sender
    
    //B
    signals:
    void B::newData_ready(QString data); //you have to pass apropriate type, assuming QString since it is from QLineEdit
    slots:
    void B::on_SendButton_clicked()
    {
        emit newData_ready(userData_LineEdit->text());
    }
    
    //A
    slots:
    void A::on_newData_ready(QString data)
    {
        QTableWidgetItem *item = new QTableWidgetItem(data);
       //here add item where u want
    }
    
    connect(B, SIGNAL(newData_ready(QString)), A, SLOT(on_newData_ready(QString)));
    

    Just a scheme so it probably wont work like that but I hope you get the point.


Log in to reply
 

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