c++ - QT/C++ Commit a value to other class

标签 c++ qt

我在 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/

相关文章:

c++ - 为什么 CLion 在 FreeBSD 上无限期地卡在 "Building..."上?

c++ - 线程代码解释器中的手动操作调用(打破正常流程)

c++ - 如何加快这个盒子堆叠变化?

c++ - Qt C++ 将秒转换为格式化字符串 (hh :mm:ss)

qt - QSocketNotifier : socket notifiers cannot be disabled from another thread

c++ - 将 Vector 转换为 QJsonArray 的最快方法?

c++ - 接口(interface)和实现 C++

c++ - Qt 托盘图标拖放

c++ - Qt 程序在 QPainter::drawPixmap() 上崩溃

c++ - 绕道获得全局指针?