C++ 如何在my Qdialogbox';什么是线人?
在我的主窗口中,我有一个名为C++ 如何在my Qdialogbox';什么是线人?,c++,qt,qlineedit,qmainwindow,qdialog,C++,Qt,Qlineedit,Qmainwindow,Qdialog,在我的主窗口中,我有一个名为employee_list的QlistWidget,该QlistWidget中的项目如下: <FIRM-1> name="Anna Ken" age="25" job="QtMaster" , <FIRM-2> name="Sir Ron" age="50" job="QtSlave" 由于我们无法看到您的GrpComd代码
employee_list
的QlistWidget
,该QlistWidget
中的项目如下:
<FIRM-1> name="Anna Ken" age="25" job="QtMaster" ,
<FIRM-2> name="Sir Ron" age="50" job="QtSlave"
由于我们无法看到您的
GrpComd
代码,因此无法知道您是否初始化了该指针。或者即使它是公共
成员
无论如何,您应该在调用dialog
exec()
之前设置文本。而QLineEdit
的方法是setText
而不是“setText”--注意大写字母“T”您必须填写并显示,即setText()
,然后show()
或exec()
:
@eyllanesc,谢谢你的编辑,我的声誉不到10,我无法正常发布图片。谢谢,这帮助了我的问题。
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
}
}
if (test_s.find("<FIRM-1>") != std::string::npos)
{
GrpComd grpComd;
grpComd.setName(clickedName);
grpComd.setJob(clickedJob);
grpComd.setAge(clickedAge);
grpComd.exec();
}
GrpComd::GrpComd(const QString& name,const QString& job, uint age);