我在 QT 中遇到一些问题,无法将 QModelIndex 从类 myDialog 提交到 mainWindow 类。
在 myDialog.cpp 中我有以下函数:
void myDialog::accept(){
QModelIndex index = ui->folderElectionView->currentIndex();
connect(SIGNAL(folderElection::accept()), this, Slovari::folderElected(index));
//Slovari s;
//s.on_folderElected(index);
}
并在 mainWindow 中作为公共(public)插槽:
void folderElected(QModelIndex index){
...do something with the index
}
我也用评论中的代码尝试过,但我认为通常信号和插槽是正确的方法!?
最佳答案
您的代码在很多方面都有问题。看起来它甚至没有编译。 我可以修复它,但我认为这是个坏主意,因为你的代码逻辑看起来也有问题,所以修复它对你也没有帮助。
IMO 你应该描述你想要实现什么样的功能。 我怀疑这应该看起来或多或少像这样:
myDialog::myDialog(QWidget *parent) :
QDialog(parent) {
...
connect(this, SIGNAL(accept(QModelIndex)),
somthingEles, SLOT(folderElected(QModelIndex));
}
void myDialog::accept(){
QModelIndex index = ui->folderElectionView->currentIndex();
emit accept(index);
}
void folderElected(QModelIndex index){
...
// do something with the index
}
关于c++ - QT/C++ Commit a value to other class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25378414/