Compiler says MyGUI::newDelegate doesn't take 2 arguments

Locien

03-05-2013 01:27:24

This is the code in question:
mChatWindow = mGUI->createWidget<MyGUI::Window>("WindowCSX", 2, mWindow->getHeight()-300, 500, 300, MyGUI::Align::Default, "Overlapped");
mChatWindow->eventKeyButtonPressed += MyGUI::newDelegate(this, &Main::keyPressed);


Gives me the error: main.cpp(499): error C2660: 'MyGUI::newDelegate' : function does not take 2 arguments

For some reason my compiler(MSVC2010) says that newDelegate doesn't take two arguments, I'm absolutely at a loss as to what to do. After some googling I found this page which states that there's a bug in Visual Studio so you have to use a different approach. So I tried to change it to

mChatWindow->eventKeyButtonPressed += MyGUI::newDelegate(static_cast<Main *>(this), &Main::keyPressed);

But I get the exact same error. What am I supposed to do to get it to work? Does anyone know a fix for this problem? I'm using the latest stable version.

Thanks in advance.

Edit: Another problem. Why doesn't mChatWindow->setCaption("Hello world!"); display any text? The way I understood it is that setCaption is used to display text, am I doing something wrong?

Altren

03-05-2013 14:11:54

Show your classes structure and show where is keyPressed declared. It matter if you call newDelegate from 'Main' class function or not.
What about compiler - check that you have SP1 installed for Visual Studio. It is not requirement, but it is strongly recommended to install SP1.

What about setCaption, well, your code is correct. Check, that it is being called.

Locien

04-05-2013 15:09:53

All of the following are in class Main : public Ogre::FrameListener, public Ogre::WindowEventListener, public OIS::KeyListener, public OIS::MouseListener

in the class:
bool keyPressed(const OIS::KeyEvent &arg);
MyGUI::WindowPtr mChatWindow;
MyGUI::Gui* mGUI;
MyGUI::OgrePlatform* mPlatform;


In the void CreateScene function these functions are called:
mPlatform = new MyGUI::OgrePlatform();
mPlatform->initialise(mWindow, mSceneMgr);
mGUI = new MyGUI::Gui();
mGUI->initialise();

mChatWindow = mGUI->createWidget<MyGUI::Window>("WindowCSX", 2, mWindow->getHeight()-300, 500, 300, MyGUI::Align::Default, "Overlapped");

mChatWindow->eventKeyButtonPressed += MyGUI::newDelegate(this, &Main::keyPressed); //Error: no instance of overloaded function "MyGUI::newDelegate" matches the argument list

mGUI->setVisiblePointer(false);

Altren

05-05-2013 22:27:56

You have wrong Main::keyPressed arguments. Look at eventKeyButtonPressed declaration, there is event description:
/** Event : Key pressed.\n
signature : void method(MyGUI::Widget* _sender, MyGUI::KeyCode _key, MyGUI::Char _char)\n
@param _sender widget that called this event
@param _key code
@param _char of pressed symbol (for multilanguage applications)
*/