[Qt-interest] [PyQT] Distinguish between designer and runtime code.
Andreas Pakulat
apaku at gmx.de
Tue Apr 21 14:46:32 CEST 2009
On 21.04.09 12:22:28, Emiliano Mennucci wrote:
> I have two processes which exange messages each other.
> Process A is a normal (i.e non-qt) program which sends messages to process
> B.
> Process B is a QT GUI application showing received messages into a text box.
>
> I created a customized widget (called ShowMessages) which inherits from
> QPlainTextEdit and reads messages from a pipe when a timer expires, and
> appends them in the text box.
> Code is not really designed like this (which would be pretty bad design I
> think), but it's just to make things simple here.
> For reasons I won't tell, process A cannot be shut down while I'm creating
> the form using qt-designer.
>
> Problem is that while I'm using qt designer (thus selecting the ShowMessages
> widget and putting it within the window) the widget begins to show messages,
> even if I'm in the designer. This feature is cool but the problem is that
> when I save the form, already present messages are saved in .ui file, which
> results in turn in bad behaviour when I start process B (because process
> starts showing messages I received during the creation phase).
>
> I could clean the text box just after process B starts, but I think that
> avoiding messages to be present in the .ui file is much better. What I want
> is to be able to write code like this for the widget:
>
> if <I'm not in the designer>
> timer = QtCore.QTimer(self)
> QtCore.QObject.connect(timer, QtCore.SIGNAL("timeout()"), self,
> QtCore.SLOT("on_timer()"));
> timer.start(2000)
>
> Is there an qt function to know if I'm in the designer? Do you think that
> distinguishing between designer and runtime code is "bad"?
Yes this is bad, your widget should be designed to only capture the windows
messages after having called a start() method on it, not automatically.
Andreas
--
You will be run over by a beer truck.
More information about the Qt-interest-old
mailing list