开发者

Symbian qt threading

1) In symbian c++ thread is not recommended. Instead of that they recommend active object for multi tasking. Presently I am using QT to develop a application in symbian. Since there is no active object in QT I thought of using thread. My question is , can I use thread, is it is recommended. If it is not recommended, how to achieve multitasking.

2) I have created a sample thread class as shown bellow. When I call test function from the constructer of the main window thread will start but UI will be in hung state, infact main window itself will not be displayed. Please help me to solve the problem.

class CSampleThread: public QThread

{
    Q_OBJECT

public:
    CSampleThread(QObject *parent = 0) : QThread(parent)
    {}

    virt开发者_高级运维ual ~CSampleThread()
    {}

    void test(){
        QThread::start(LowPriority);
    }

protected:

    void run()
{
    while(true){}

    }
};


Could be that the "while(true)" is starving the main thread for CPU cycles. Try adding a call to yield() or sleep() in the loop body.


You are right in saying that, for the development of most programs in Symbian C++, the use of co-operative multitasking (a.k.a. Active Objects) is preferred over pre-emptive multitasking (i.e. threads). When an asynchronous operation may take a long time however, it is probably a good idea to perform it in a separate thread. While it is possible to implement long-running operations using active objects, doing so may cause the application to become unresponsive, because the active scheduler will be unable to handle input events while executing the long-running RunL() function.

Similarly, in Qt, usage of threads is only required when your application needs to perform a long-running task. Event handling which would be handled using AOs in native Symbian code is taken care of by Qt's event system, with asynchronous notifications delivered via signals and slots. Unsurprisingly, the Qt event loop on Symbian is implemented using active objects.

So, while we can provide help on the usage of QThread, the question of whether this is the right solution depends on the nature of the problem you are trying to solve.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜