[Qt-interest] Would need some comments please
Gordon Schumacher
gordon at rebit.com
Fri Nov 27 20:15:55 CET 2009
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Going to CC: back to the list since there's more ideas here that might
be useful to others...
Kari Laine wrote:
> Hi Gordon,
>
> thank you for comments.
> I have one question - answer if you have time.
No worries - of late I've pretty often barely had time for sleep, but
things are calm for the moment :)
> So the idea having separate classes for differen UI-parts is a correct
idea?
I'm guessing that by "different UI parts" you mean different dialogs
and the like? Absolutely, in that case.
The other thing to bear in mind is that if you have a chunk of UI -
say, the controls for a channel - that you need to use in more than
one place, you can make that a single QWidget-derived class, and
instantiate it wherever you need it. So for four different channels,
you could have something like:
class ChannelUI : public QWidget
{
Q_OBJECT;
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged);
Q_PROPERTY(double voltage READ voltage WRITE setVoltage NOTIFY
voltageChanged);
public:
ChannelUI(QString const& n, double v = 1.0, QObject* parent = NULL)
: QWidget(parent) {setName(n); setVoltage(v);}
ChannelUI(QString const& n, QObject* parent) : QWidget(parent)
{setName(n);}
~ChannelUI() {}
QString name(void) {return m_name->text();}
double voltage(void) {return m_voltage->text().toDouble();}
public slots:
void setName(QString n) {m_name->setText(n);}
void setVoltage(double v) {m_voltage->setText(QString::number(v));}
signals:
void nameChanged(QString n);
void voltageChanged(double v);
QLabel m_name;
QLabel m_voltage;
}
...
ScopeControls::ScopeControls()
{
QVBoxLayout* layout = new QVBoxLayout;
ChannelUI* channel1 = new ChannelUI("ch1");
layout->addWidget(channel1);
ChannelUI* channel2 = new ChannelUI("ch2");
layout->addWidget(channel2);
}
Note also that using the properties stuff from the beginning is a
wonderful thing - not only does it handle some of the repetitive grunt
work, but if you decide later that you want to let people script it
via QtScript, or you'd like IPC via D-Bus or COM... well, 99% of your
work is already done.
> I think this is very good advice - I was wondering where to put the slots.
That would depend again on whether it is purely a UI trigger or a
business logic trigger. So with the above example - the "nameChanged"
and "voltageChanged" are properties of the UI, but "triggerHit" would
be a business logic thing.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.12 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
iEYEARECAAYFAksQJWsACgkQ2yRp4mXKHF16twCfallYf90EeYm5wAZQIxTd2owe
IO8An1+4jqMMg+7OxuA0oosHr1Q/kReX
=AUvL
-----END PGP SIGNATURE-----
More information about the Qt-interest-old
mailing list