C++ QT/C++;将值提交给其他类

C++ QT/C++;将值提交给其他类,c++,qt,C++,Qt,我在QT中遇到一些问题,无法将QModelIndex从类myDialog提交到主窗口类 在myDialog.cpp中,我有以下功能: void myDialog::accept(){ QModelIndex index = ui->folderElectionView->currentIndex(); connect(SIGNAL(folderElection::accept()), this, Slovari::folderElected(index)); //Slovari s;

我在QT中遇到一些问题,无法将QModelIndex从类myDialog提交到主窗口类

在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
}

通常,您将信号连接到您知道插槽的位置,而不是信号所在的位置。