slot中传参数出了有关问题
slot中传参数出了问题C/C++ codeQTreeWidgetItem *item new QTreeWidgetItem(0)item-setText(0,name)
slot中传参数出了问题
C/C++ code QTreeWidgetItem *item = new QTreeWidgetItem(0); item->setText(0,name); friendView->addTopLevelItem(item); messageView->append(item->text(0)); connect(friendView, SIGNAL(itemClicked(QTreeWidgetItem*, int)), this, SLOT(openNewDialog(QString))); // 这里我想把item->text(0)作为openNewDialog()的参数传过去
C/C++ codevoid MyMainWindow::openNewDialog(QString name ){ //messageView->append("sign"); MyDialog *md = new MyDialog(name); md->show(); md->raise(); md->activateWindow();}
然后运行程序后,点击item 没有反应,???
[解决办法]LZ错了 信号槽的信号函数和槽函数的形参类型必须一致才能进行参数传递
connect(friendView, SIGNAL(itemClicked(QTreeWidgetItem*, int)),
this, SLOT(openNewDialog(QString)));
openNewDialog(QString)得才成openNewDialog(QTreeWidgetItem*, int),保持两个函数形参一致
[解决办法]你可以传过去(QTreeWidgetItem* ,int),然后再用 item->text(0),作为你想处理的字段读取!