PDA

View Full Version : Passing DB Query data to another Window and show the values in respective fields



abhiabhi
19th February 2013, 12:45
Hi, I was able send Selecteditem of QListView to a QLineEdit in next window, now I need to send that Selecteditem’s Query information to Second Window’s Form fields. Do I need to use QStringList to hold all the information? Or any other way? guide me thanks :)

Here is the source of firstwindow.cpp:


void MainWindow::showValue(){



GetValue *v = new GetValue(ui->listView->currentIndex().data().toString());

this->hide();

v->show();

v->setWindowTitle("Form Information");

}

The Second WIndow’s code:


GetValue::GetValue(const QString &text,QWidget *parent) :

QMainWindow(parent),

ui(new Ui::GetValue)

{

ui->setupUi(this);

ui->lineEdit->setText(text);

}

Here I need to show information from first window in the form of a query like:


Select * from User where UserName="Selecteditem";

All the information relating to that row will be displayed in the Second Window’s fields.

Santosh Reddy
19th February 2013, 13:19
If you want to pass the qurey, then just pass it as a QString (assuming you wanted to execute the query in second window)

You could build the query on the second window itself, then it wont be required ot pass anything else other than selected item

abhiabhi
21st February 2013, 06:05
Yeah Santosh sir, thats right, how to save the string which is in QLineEdit ? this function ui->lineEdit->setText(text); will display the text from Window one, but I am not able convert it to QString, I tried like QString my_string; my_string = textValue->text();, but the app ended up showing the following error: The program has unexpectedly finished.

Added after 1 11 minutes:

I got the string using QString my_string = ui->lineEdit->text(); :)