Is it possible for a qtopia application to stay on an infiniteIloop from the time of its loading?
When i called the loop in the constructor the window itself is no loading....
Mahe2310
Is it possible for a qtopia application to stay on an infiniteIloop from the time of its loading?
When i called the loop in the constructor the window itself is no loading....
Mahe2310
if you are calling an infinite loop in your constructor, ofcourse the widgwt never gets contructed...
But it could be I missunderstood you.
Post the code.
Doing an infinite loop in your constructor wouldn't work. The constructor needs to return. Assuming that the object being constructed is a QObject-derivative, you could do use the QTimer::singleShot method to allow the constructor to return and yet still call the method with your infinite loop:
Qt Code:
{ Q_OBJECT public: // Constructor private slots: void MyInfiniteLoop(); }; { // Do whatever you need to do here. // Use a zero-timeout single shot timer here to allow the // constructor to exit before MyInfiniteLoop gets called. } void MyWidget::MyInfiniteLoop() { while(true) { // Do something interesting } }To copy to clipboard, switch view to plain text mode
this is bad design, both methods.
You should never call an infinite loop in a constructor.
make the loop in a public method/slot and call normally after construction.
There can be no reason for calling an infinite loop in a constructor.
And in a Qt program, if you use an infinite loop, it would be best to use a QThread obeject to house it in its run() method.
Originally Posted by Ben.Hines
thank you,
That is a good method.
Mahe2310
@Mahe2310
Could you explain why it is you need an infinite loop in a costructor?
I am sure if you explain what it is you want to acheive it can be done in a better way.
Originally Posted by high_flyer
Hi High_Flyer,
Myself want to handle the qtopia key events and some message queue events simultaneously.
I mean, handle them always. So I thought of going for an infinite loop which check for a qt event first and then message event.
Is it possible to call the MyWidget::event(QEvent*)?
I will show how the loop should look like...
Qt Code:
while(1) { { MyEventHandler(event); } if( /* Messgae at Queue */ ) { /* Handle the Message */ } }To copy to clipboard, switch view to plain text mode
And how do you expect to receive events if you are inside an infinite loop?
How about just processing events in a "normal way"? By subclassing or using an even filter, that is..
Originally Posted by jpn
i didnt get that...
can u explain it...
mahe2310
But why do you want to start your endless loop in the contructor and not just call it normally?
But even so it would not work.
What jpn means is, if the main event loop is stuck in your endless loop, it will never have time to attend the events.
You should use an event filter.
http://doc.trolltech.com/4.1/qobject...allEventFilter
The above link is to the normal Qt4, but look the same in QTopia docs, I think it should be the same or very similar.
Bookmarks