[Qt-interest] Connect objects from XML description

Stephen Jackson spjackson42 at gmail.com
Thu Dec 17 01:00:09 CET 2009


2009/12/14 Eirik Ulvik :
> Hi list,
> I would like to describe a connection between QObjects from an XML file.
> A sample file could look something like this:
> <connections>
>  <obj class="Thread1" id="obj1" />
>  <obj class="Thread2" id="obj2" />
>  <connect sender="obj1" signal="Thread1Msg(QString msg)" receiver="obj2"
> slot="receiveMsg(QString msg)" />
> </connections>
>

[snip]

>
>  QDomNodeList conns = doc.elementsByTagName("connect");
>  for(int i = 0; i < conns.size(); i++) {
>    QDomElement e     = conns.item(i).toElement();
>    QString sender       = e.attribute(QString("sender"));
>    QString signal         = e.attribute(QString("signal"));
>    QString receiver     = e.attribute(QString("receiver"));
>    QString slot           = e.attribute(QString("slot"));
>
>   QByteArray tmp_sig = signal.toLatin1();
>    const char *sig = tmp_sig.data();
>    QByteArray tmp_slo = slot.toLatin1();
>    const char *slo = tmp_slo.data();
>    connect(obj_map[sender], SIGNAL(Thread1Msg(QString msg)),
> obj_map[receiver], SLOT(Thread1Msg(QString msg)));
>  }
> }
>
> The error message printed from the connect method is: Object::connect:
> Parentheses expected, signal Thread1::sig in MainWindow.cpp:90.
>

http://doc.trolltech.com/4.5/qobject.html#connect
"Note that the signal and slots parameters must not contain any
variable names, only the type."

So remove all your msg variable names. I haven't checked whether there
is anything else wrong, but you do need to correct this first.

-- 
HTH,

Stephen Jackson




More information about the Qt-interest-old mailing list