[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: OT: Updating a GUI thread from another one
From:       Kevin Krammer <kevin.krammer () gmx ! at>
Date:       2003-12-02 8:51:24
[Download RAW message or body]

[Attachment #2 (multipart/signed)]


On Tuesday 02 December 2003 08:10, Giuseppe Torelli wrote:
> Alle 19:02, luned́ 1 dicembre 2003, Kevin Krammer ha scritto:
> > You create a user defined Event (subclassing from QEvent using a Type >=
> > 1000)

class MyEvent : public QEvent
{
public:
    const int TYPE = 1001;
    MyEvent() : QEvent(TYPE) {}
};

> > You create a QObject subclass that implementes event() and if the event
> > it gets is your type, calls update() on the Widgets.

class MyListView : public QListView
{
public:
    bool event(QEvent* event) {
        if (event->type() == MyEvent::TYPE) {
            update();
            return true;
        }

        return QListView::event(event);
    }
};

> > In your thread you post instances of your event class to the receiver
> > object.

class MyThread : public QThread
{
public:
    MyThread(QObject* receiver) : QThread(), m_receiver(receiver) {}

private:
    QObject* m_receiver;
};


in run() whenever the GUI needs to update:
QApplication::postEvent(m_receiver, new MyEvent());

Cheers,
Kevin

[Attachment #5 (application/pgp-signature)]

>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic