【发布时间】:2014-09-10 11:27:54
【问题描述】:
我不明白某些类的构造函数中函数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中)
【问题讨论】:
-
嗯,你有没有尝试过按下一个键时会发生什么?事件不是要在屏幕上显示内容,而是将(用户)输入传递给处理它的程序部分。
-
@datenwolf 是的,我的意思是,当我按下一个键时,一切都会发生,就像构造函数中没有任何“连接”一样。所以我的问题是:我什么时候需要使用连接?
标签: c++ events opengl wxwidgets