How to populate values in my Qdialogbox's linedits?
-
in my main window, i have a qlistwidget named
employee_listand the items in this qlistwidget are like this
<FIRM-1> name="Anna Ken" age="25" job="QtMaster",
<FIRM-2> name="Sir Ron" age="50" job="QtSlave"so when i click the items in
employee_listqlistwidget, a dialogbox shows up with 3 fieldsname,age,joblike this

but when this dialog box shows up, i want the fields
name,age,jobto be populated , like this, How can i achieve this ?
so far i have tried this.
void MainWindow::on_employee_list_itemDoubleClicked(QListWidgetItem* item) { QString test = item->text(); // getting the item text std::string test_s = test.toStdString(); //converting it to string from Qstring string name_part = ""; //creating a variable in which name will be stored int name_pos = test_s.find("name=\""); for (int i = name_pos + 6; i < test_s.length();i++) { if (test_s[i] != '\"') name_part += test_s[i]; else break; //extracting name in the item's text, after this the name_part variable value is Sir ron. // similar code for extarcting age and job. if (test_s.find("<FIRM-1>") != std::string::npos) //if item contains text <FIRM-1> then show this dialogue { GrpComd grpComd; //creating instance of dialog grpComd.exec(); //showing it grpComd.name_lineedit->settext(name_part); // i tried this to populate name in name_linedit but getting error , access violation reading location } } -
in my main window, i have a qlistwidget named
employee_listand the items in this qlistwidget are like this
<FIRM-1> name="Anna Ken" age="25" job="QtMaster",
<FIRM-2> name="Sir Ron" age="50" job="QtSlave"so when i click the items in
employee_listqlistwidget, a dialogbox shows up with 3 fieldsname,age,joblike this

but when this dialog box shows up, i want the fields
name,age,jobto be populated , like this, How can i achieve this ?
so far i have tried this.
void MainWindow::on_employee_list_itemDoubleClicked(QListWidgetItem* item) { QString test = item->text(); // getting the item text std::string test_s = test.toStdString(); //converting it to string from Qstring string name_part = ""; //creating a variable in which name will be stored int name_pos = test_s.find("name=\""); for (int i = name_pos + 6; i < test_s.length();i++) { if (test_s[i] != '\"') name_part += test_s[i]; else break; //extracting name in the item's text, after this the name_part variable value is Sir ron. // similar code for extarcting age and job. if (test_s.find("<FIRM-1>") != std::string::npos) //if item contains text <FIRM-1> then show this dialogue { GrpComd grpComd; //creating instance of dialog grpComd.exec(); //showing it grpComd.name_lineedit->settext(name_part); // i tried this to populate name in name_linedit but getting error , access violation reading location } }@learnist Did you check is their any string coming from Item->text(); ?
-
in my main window, i have a qlistwidget named
employee_listand the items in this qlistwidget are like this
<FIRM-1> name="Anna Ken" age="25" job="QtMaster",
<FIRM-2> name="Sir Ron" age="50" job="QtSlave"so when i click the items in
employee_listqlistwidget, a dialogbox shows up with 3 fieldsname,age,joblike this

but when this dialog box shows up, i want the fields
name,age,jobto be populated , like this, How can i achieve this ?
so far i have tried this.
void MainWindow::on_employee_list_itemDoubleClicked(QListWidgetItem* item) { QString test = item->text(); // getting the item text std::string test_s = test.toStdString(); //converting it to string from Qstring string name_part = ""; //creating a variable in which name will be stored int name_pos = test_s.find("name=\""); for (int i = name_pos + 6; i < test_s.length();i++) { if (test_s[i] != '\"') name_part += test_s[i]; else break; //extracting name in the item's text, after this the name_part variable value is Sir ron. // similar code for extarcting age and job. if (test_s.find("<FIRM-1>") != std::string::npos) //if item contains text <FIRM-1> then show this dialogue { GrpComd grpComd; //creating instance of dialog grpComd.exec(); //showing it grpComd.name_lineedit->settext(name_part); // i tried this to populate name in name_linedit but getting error , access violation reading location } } -
@learnist Did you check is their any string coming from Item->text(); ?
@shashikumar Yes, i am getting string, only problem is propulating that into dialog box.
-
@shashikumar Yes, i am getting string, only problem is propulating that into dialog box.
grpComd.exec(); //showing it grpComd.name_lineedit->settext(name_part); // i tried this to populate name in name_linedit but getting error , access violation reading locationThe second line compiles, does it? With
settext?Your code compiles with theOK, I see you've done some editing of the code you have to shorten.{s &}s you show, right?Did you try doing the second line before the first one, if you want to put the text in before you showed the user the modal dialog?
-
Hi,
exec is a blocking call so basically you modify your dialog content after you dismiss it.