向其他类提交一个值

QT/C++ Commit a value to other class

本文关键字:一个 其他 提交      更新时间:2023-10-16

我在QT中有一些问题,从myDialog类提交QModelIndex到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);
}

void folderElected(QModelIndex index){
...do something with the index
}

我也试过用注释中的代码,但我认为一般信号和槽是正确的方式!?

你的代码在很多方面都有问题。看起来它甚至不能编译。我可以修复它,但我认为这是一个坏主意,因为你的代码逻辑看起来也有问题,所以修复这个也不会帮助你。

在我看来,你应该描述你想要实现什么样的功能。我怀疑这看起来应该或多或少像这样:

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
}
相关文章: