[GUI] Using OpenFileDialog

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Gav
Posts: 23
Joined: Fri Jul 16, 2004 12:28 pm

[GUI] Using OpenFileDialog

Post by Gav »

well at the moment, in the GUI event management here is the relevant code:

Code: Select all

				if (id == 103)
				{
					listbox->addItem(L"File open");
					openNewObject = guienv->addFileOpenDialog(L"Please choose a file.", true, 0, -1);
					return true;
				}
and in the main loop:

Code: Select all

		if(openNewObject != 0)
		{
			currentMesh = smgr->getMesh((const char *)openNewObject->getFilename());
			currentMeshNode = smgr->addAnimatedMeshSceneNode(currentMesh);
			currentMeshNode->setPosition(core::vector3df(0.0f, 0.0f, 0.0f));
			currentMeshNode->setMaterialFlag(video::EMF_LIGHTING, false);
			currentMeshNode->setMaterialTexture( 0, driver->getTexture("testTerrain.bmp") );
			openNewObject = 0;
		}
basically i am trying to load a model using the openFileDialog, but as soon as i click the button that is meant to bring up the window "choose a file to open" my program crashes, the console telling me "could not load file:"
ie: its trying to load a file as soon as I click on "open a file" rather than when I click the open button in openFileDialog..

So how do I change it?
pfo
Posts: 370
Joined: Mon Aug 29, 2005 10:54 pm
Location: http://web.utk.edu/~pfox1

Post by pfo »

You're doing it incorrectly. When you call guienv->addFileOpenDialog, it returns instantly. You need to pass an ID to addFileOpenDialog, and then wait for the OPEN_FILE_DIALOG event in your event receiver. The file dialog will be SEvent.GUIEvent.Caller; you can get the path from there.
Gav
Posts: 23
Joined: Fri Jul 16, 2004 12:28 pm

Post by Gav »

ah thanks :)
Post Reply