在构造函数中使用connect()函数
use of function connect() in the constructor
我不明白在某些类的构造函数中使用函数connect()。我认为这是为了"连接"事件与我的程序的图形部分,但它使我一样,如果我不使用任何连接函数的构造函数。下面是我的一部分代码,例如:
#include "VueOpenGL.h"
#include "wx/wx.h"
#include "wx/glcanvas.h"
#include "wx/progdlg.h"
using namespace std;
//Constructor of the class "VueOpenGL"
VueOpenGL::VueOpenGL(wxWindow* parent, wxSize const& taille, wxPoint const& position)
:wxGLCanvas(parent, wxID_ANY, position, taille,
wxSUNKEN_BORDER|wxFULL_REPAINT_ON_RESIZE|WX_GL_DOUBLEBUFFER)
{
//Events
Connect(wxEVT_KEY_DOWN, wxKeyEventHandler(VueOpenGL::OnKeyDown));
}
...
void VueOpenGL::OnKeyDown(wxKeyEvent& event) {
switch(event.GetKeyCode()) {
case WXK_LEFT:
instructions_1;
break;
case WXK_RIGHT:
instructions_2;
break;
}
}
(所有的原型都在VueOpenGL.h)
你没有把一切都告诉我们。如果没有Connect(wxEVT_KEY_DOWN)
,按键事件就不会被传递给你的处理器。因此,如果它仍然被调用,它必须以其他方式连接,或者也许你只是没有测试你认为你正在测试的代码(例如,在注释掉包含Connect()失败的行后重建,你仍然运行旧版本)。
相关文章:
- "error: no matching function for call to"构造函数错误
- 什么时候调用组成单元对象的析构函数
- 继承函数的重载解析
- 为什么随机数生成器不在void函数中随机化数字,而在main函数中随机化
- C++模板来检查友元函数的存在
- 递归函数计算序列中的平方和(并输出过程)
- 如何使用connect将qml按钮与同一类的cpp函数连接起来
- 如何将函数指针传递给方法,以便它可以在Qt的connect()中使用?
- 为什么 connect() 函数看不到插槽?
- 将QMETAMETHOD作为参数传递到使用新的Qobject :: Connect语法的函数
- 如果对QObject::connect()使用lambda函数,则使用gcc编译失败
- 无法连接Qt QObject::connect()函数
- connect() 函数停止程序
- QObject::connect 周围的函数包装器
- Winsock 的 connect() 函数中的超时
- 使用QObject::connect()时,类型签名是否重要,用于将函数连接到信号
- QT 5 connect()函数连接textEditor和主窗口
- 在构造函数中使用connect()函数
- 为什么 boost::signals2::signal:<T>:connect 需要复制构造函数?
- Connect()函数失败wsagetlasterror() 10038