向其他类提交一个值
QT/C++ Commit a value to other class
我在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
}
相关文章:
- 有没有什么方法可以使用一个函数中定义的常量变量,也可以由c++中同一程序中的其他函数使用
- 当我在其中一个线程执行中(在activemq-cpp中)捕获到特定值时,我如何终止/停止所有其他线程
- 如何封装一个函数,以便它只能由同一类中的一个其他函数调用?
- 有没有办法使用 strcpy 将字符串数组复制到另一个字符串或其他数组中?
- 我想在 Main 中用 C++ 调用其他类中的一个类,但我做不到
- 为什么这个选择排序算法仍然切换一个元素,当它已经是其他元素中最小的元素时?
- error dllimport 函数的定义不允许在一个特定的联合中,而其他类、结构和联合将按预期导出
- 当一行中只有一个"#"而没有其他内容时,C++预处理器会做什么?
- 当只有一个线程主要使用该对象而其他线程很少使用它时,如何最小化该对象的互斥锁锁定?
- 为什么最后一个推回向量的对象的字段会转移到向量的其他对象?
- 只对向量中的一个类成员进行排序,其他成员保持不变
- 从 int 中剥离位时,编译器会警告一个转换,但不警告其他转换.有解决方法吗?
- 使用 CMake 与其他静态库链接的静态库 - 一个有效,一个无效。为什么?
- 创建一个 const std::vector ,其中包含另一个 const std::vector 和其他值
- 我如何在一个 if 语句中声明所有数字我尝试通过其他方式声明所有数字,如果一个接一个,但似乎代码有逻辑错误
- 检查IP是否在其他IP网络范围内,并查找下一个可用IP
- 如何创建一个接口,允许我访问C++中的按钮(和其他ui)函数,该函数是使用python中的MFC实现的
- 如何创建一个函数来执行其中的其他函数
- 如何检查一个字符串是否包含多个其他字符串?
- 是否可以将多个结构作为一个数据包存储在一个函数中,然后传递给其他函数并在那里提取?