0

The following code is used by me in order to send the value in a table view in one window to the line edit in another window. but i get an error! how can i correct it?

void firstWindow::on_tableView_activated(const QModelIndex &index)
{

    QString val=ui->tableView->model()->data(index).toString();
    firstWindow conn;
     conn.connOpen();
    QSqlQuery qry;
    qry.prepare("Select MESSAGE_ID from Message where  MESSAGE_ID='"+val+"'");
    if(qry.exec())
    {
        while(qry.next())
        {
           Window2 a;

          ui->message->setText(qry.value(0).toString());

    }
}


    conn.connClose();


}

here firstwindow is one class which has a connOpen() method to connect to a database( works properly), when the user clicks a row retrieved from the database i want it to appear in a line edit named message in a window which belongs to a class named window2. But I get an error stating that message is not a member of firstWindow class! How can i correct this issue?

  • Which line generates that error message ?, also can show the complete code of the class `firstWindow`. – eyllanesc Aug 18 '17 at 14:01
  • Is message defined in the same ui file as tableView? From your description I would expect it is not. And you should use signals and slots to solve the problem. – drescherjm Aug 18 '17 at 14:25
  • 1
    @eyllanesc " ui->message->setText(qry.value(0).toString());: this generates the error because I think message is a line edit componennent belonging to the window2 class but its done inside a method in firstwindow class – Sachini Karunaratne Aug 18 '17 at 15:22
  • @drescherjm message is a line edit – Sachini Karunaratne Aug 18 '17 at 15:22
  • show the complete code of the class firstWindow – eyllanesc Aug 18 '17 at 15:27
  • ***message is a line edit*** Should be very easy to use signals and slots for that. Create a signal with a QString parameter in firstWindow connect that to a slot on secondWindow (again with a QString parameter). In the slot update the message directly. – drescherjm Aug 18 '17 at 15:33

0 Answers0