Hello,

I'm stumbling on a strange proiblem with Event2...

I've modified a little bit TheadEvenTest.cpp to exepriment (see attached file):

Insetad of passing the result of boost::bind directly to Event2::connect method,

i'm assigning the result of boost::bind to a boost::function variable and then passing it to the Event2::connect method
and getting strange compile errors...

It seems the compiler is unable to choose the correct alternative of operation== when comparing slots.


Any ideas?

Thanks
Vadim
/*
 * WengoPhone, a voice over Internet phone
 * Copyright (C) 2004-2007  Wengo
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include "ThreadEventTest.h"

#include <util/Logger.h>

#include <thread/Thread.h>

#include <qtutil/QtThreadEvent.h>
#include <qtutil/ThreadEventFilter.h>

#include <QtGui/QtGui>

class Message {
public:

	Message(int i) {
		_i = i;
	}

	std::string toString() const {
		return std::string("message=" + String::fromNumber(_i));
	}

private:

	int _i;
};

class Model : public Thread {
public:

	Event2<void ()> messageSentEvent;

	Event2<void (const std::string & message)> messageSentEvent2;

	Event2<void (const Message * message)> messageSentEvent3;

	Event2<void ()> destroyPresentationEvent;

	Model() {
	}

	void setPresentation(Presentation * presentation) {
		_presentation = presentation;
	}

	void run() {
		static int i = 0;
		while (i < 10) {
			LOG_DEBUG("messageSentEvent");
			messageSentEvent();
			messageSentEvent2("message=" + String::fromNumber(i));
			messageSentEvent3(&Message(i));
			msleep(300);
			i++;
		}
		destroyPresentationEvent();
		msleep(300);
	}

private:

	Presentation * _presentation;
};

class QtPostEvent : public IPostEvent {
public:

	QtPostEvent(QObject * receiver) {
		_receiver = receiver;
	}

	void postEvent(IThreadEvent * threadEvent) {
		LOG_DEBUG("postEvent");
		QCoreApplication::postEvent(_receiver, new QtThreadEvent(threadEvent));
	}

private:

	QObject * _receiver;
};

Presentation::Presentation(Model & model)
	: QPushButton("Hello world!") {

	//Filter for post event (=thread event)
	ThreadEventFilter * threadEventFilter = new ThreadEventFilter();
	QCoreApplication::instance()->installEventFilter(threadEventFilter);

	QtPostEvent * postEvent = new QtPostEvent(this);
	model.messageSentEvent.connect(this, boost::bind(&Presentation::messageSentEventHandler, this), postEvent);
        
    boost::function<void(const std::string & message)> fn2 =  boost::bind(&Presentation::messageSentEventHandler2, this, _1);   
	//model.destroyPresentationEvent.connect(this, boost::bind(&Presentation::destroyEventHandler, this), postEvent);
	model.messageSentEvent2.connect(this, fn2 , postEvent);
	model.messageSentEvent3.connect(NULL, boost::bind(&Presentation::messageSentEventHandler3, this, _1), postEvent);
	model.messageSentEvent3.connect(NULL, boost::bind(&Presentation::messageSentEventHandler3, this, _1), postEvent);
	model.messageSentEvent3.connect(NULL, boost::bind(&Presentation::messageSentEventHandler3, this, _1), postEvent);
	model.messageSentEvent3.connect(NULL, boost::bind(&Presentation::messageSentEventHandler3, this, _1), postEvent);

	/*messageSentEvent2.connect(NULL, boost::bind(&Presentation::messageSentEventHandler2, this, _1), NULL);*/
	model.messageSentEvent2.connect(messageSentEvent2);
}

void Presentation::messageSentEventHandler() {
	LOG_DEBUG("messageSentEventHandler");
	static int i = 0;
	setText("event posted " + QString::number(i++));

	QMainWindow * window = new QMainWindow(this);
	window->show();
}

void Presentation::messageSentEventHandler2(const std::string & message) const {
	LOG_DEBUG(message);
}

void Presentation::messageSentEventHandler3(const Message * message) const {
	LOG_DEBUG(message->toString());
}

void Presentation::destroyEventHandler() {
	LOG_DEBUG("QObject::deleteLater()");
	deleteLater();
}

int main(int argc, char * argv[]) {
	Model model;
	model.start();

	QApplication app(argc, argv);

	Presentation presentation(model);
	presentation.resize(100, 30);
	presentation.show();

	model.setPresentation(&presentation);

	return app.exec();
}
_______________________________________________
Wengophone-devel mailing list
Wengophone-devel@lists.openwengo.com
http://dev.openwengo.com/mailman/listinfo/wengophone-devel

Reply via email to