Needing a QEventLoop for a kioslave

Friedrich W. H. Kossebau kossebau at kde.org
Tue Feb 10 21:22:13 GMT 2009


Le lundi, 9. février 2009, à 19:01, Thiago Macieira a écrit:
> Em Segunda-feira 09 Fevereiro 2009, às 17:15:36, Friedrich W. H. Kossebau
>
> escreveu:
> > Hi,
> >
> > am I correct that KIO::SlaveBase does not use a QEventLoop in
> > dispatchLoop()?
>
> You're correct.

Oh, I feared to be.

> > What shall I do if the 3-party code I use as backend to generate/pull the
> > data for the ioslave depends on a running event loop? E.g. if using a
> > QTimer IIUC? Could there be an option for the dispatchLoop() to also care
> > for QEvents? Or can I use a thread? Is there any example code I could
> > look at?
>
> Use a thread.

What to do then with static QObjects created by K_GLOBAL_STATIC inside the 
3-party code? It is said all QObject created in the thread have to be deleted 
before the thread ends. So if I wrap the execution of the non-gui (KDE) 
library code in a thread not the main QCoreApplication::exec() one, can/will 
K_GLOBAL_STATIC bind them to the thread somehow?

I for now tried a q'n'd approach I found for the JabberDisco in Kopete. But it 
does not work for me, is this non-ported KDE 3 code or is there a flaw?

--- 8< ---
bool breakEventLoop = false;

class EventLoopThread : public QThread
{
public:
	void run ();
};

void EventLoopThread::run ()
{
	while ( true )
	{
		qApp->processEvents ();
		msleep ( 100 );

		if ( breakEventLoop )
			break;
	}
}

void JabberDiscoProtocol::dispatchLoop ()
{
	EventLoopThread eventLoopThread;

	eventLoopThread.start ();
	SlaveBase::dispatchLoop ();
	breakEventLoop = true;
	eventLoopThread.wait ();
}
--- 8< ---

Thanks
Friedrich
-- 
Okteta - KDE 4 Hex Editor - http://utils.kde.org/projects/okteta




More information about the kde-core-devel mailing list