如何调用showEvent()
How to make showEvent() get called?
在QWidget
派生类中调用showEvent()
需要什么?
ConfigMenuForm.h
//simplified the code of the class declaration
class ConfigMenuForm : public QWidget
{
Q_OBJECT
public:
explicit ConfigMenuForm(QWidget *parent = 0);
~ConfigMenuForm();
signals:
public slots:
private slots:
protected:
void showEvent(QShowEvent *event) override; //with or without the override keyword, no change
private:
}
ConfigMenuForm.cpp
//amongst others
void ConfigMenuForm::showEvent(QShowEvent * event)
{
//do some stuff here - really simple
}
当我show()
我的小部件时,我无法触发它。。。我的意思是,代码没有效果,当放置断点时,它不会停止,所以我认为事件没有被触发。
我做错了什么?
编辑-添加更多代码和精度:
我使用的是Qt Creator 3.0.0和Qt 5.2.0(MSVC 2010,32位)
//creating the widget in the main window's constructor (class Viewer)
// ConfigMenuForm calls hide() in its own constructor
m_configMenuForm = new ConfigMenuForm(this);
然后当我按下主窗口上的按钮时
void Viewer::ontBConfigClicked()
{
m_configMenuForm->show();
}
让我困惑的是,m_configMenuForm
实际上显示在主窗口的顶部,它变得可见并正常工作!只是没有调用showEvent。
我在回答我自己的问题,因为最终这不是编程问题。编译/调试的东西一定出了问题。
记录在案,如果代码中的一切都是正确的,但由于某种奇怪的原因没有调用函数(也许这只能在Qt的事件处理程序重新实现的情况下发生?),该怎么办。
这是使用Qt Creator 3.0.0和Qt 5.2.0 MSVC2010-32位时发生的
- 清理项目:菜单构建->全部清理
- 关闭Qt呼吸器
- 转到您的构建项目/debug文件夹并删除.exe、.pdb和.ilk文件
-
转到你的构建项目/缓存文件夹,删除与你的项目同名、后缀为.pdb的文件夹(你的项目.pdb文件夹)-不确定这是否必要,但我做到了,所以我也把它写在这里
-
重新启动QtCreator、qmake、构建并运行/debug(以及tadaaa!)
"简单"的清理并没有奏效,甚至连电脑重启都没有。我不得不手动删除QtCreator没有删除的文件。
我希望它能在未来帮助别人,节省几个小时。
要在visual studio中设置断点,请参阅:断点
当您恢复窗口以获取更多信息时调用showEvent()showEvent
代码段:-
#include <QtGui>
#include <iostream>
//Move this class to any header file then exceute
class widget : public QWidget
{
Q_OBJECT
protected :
void showEvent( QShowEvent * event )
{
QWidget::showEvent(event);
}
};
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
widget w;
w.show(); //Here showEvent() get called
return app.exec();
}
相关文章:
- 什么时候调用组成单元对象的析构函数
- 对RValue对象调用的LValue ref限定成员函数
- 为什么使用 "this" 指针调用派生成员函数?
- 函数调用中参数的顺序重要吗
- OpenGL - 在抛出"__gnu_cxx::recursive_init_error"实例后终止调用?
- 基于另一个成员参数将函数调用从类传递给它的一个成员
- 为什么我的C#代码在调用回C++COM直到Task时会暂停.等待/线程.加入
- 在c++类上调用void函数
- 为什么 std::unique 不调用 std::sort?
- 调用专用模板时出错"no matching function for call to [...]"
- 选择要调用的构造函数
- C++为什么尽管我调用了void函数,它却不起作用
- 构造函数正在调用一个使用当前类类型的函数
- 变量没有改变?通过向量的函数调用
- 没有为自己的结构调用列表推回方法
- 调用'begin(int [n])'没有匹配函数
- 什么时候调用析构函数
- 如何用参数值调用函数(仅在运行时已知)
- std::cout.imbue()多重调用
- 如何调用showEvent()