[Solved] Emitting a QML custom type signal
-
Hello,
I created an object in C++ and I registered it a library in QML:
qmlRegisterType<DBusObject>("CustomComponents", 1, 0, "DBusObject");
I can acess my C++ object as a QML component:
import CustomComponents 1.0 DBusObject { id: db author: "oi" }
Now I want to pass a DBusObject component as the parameter of a QML signal:
signal buttonSend(DBusObject db)
And receive the DBusObject in C++:
QObject::connect(rect, SIGNAL(buttonSend(DBusObject)), &sender, SLOT(RegisterAndListen(DBusObject)));
But it's not working and I get the following error:
QObject::connect: No such signal Button_QMLTYPE_29_QML_31::buttonSend(DBusObject) in ../QT Dbus enviar Objeto/sisc2/main.cpp:32
Is there a way to pass a custom parameter in a QML signal? Can I only use the base types like string and int? How can I reference my DBusOBject in QML so I can use it as a signal parameter?
Any tip will be very helpful.
Thanks. -
Hello,
I created an object in C++ and I registered it a library in QML:
qmlRegisterType<DBusObject>("CustomComponents", 1, 0, "DBusObject");
I can acess my C++ object as a QML component:
import CustomComponents 1.0 DBusObject { id: db author: "oi" }
Now I want to pass a DBusObject component as the parameter of a QML signal:
signal buttonSend(DBusObject db)
And receive the DBusObject in C++:
QObject::connect(rect, SIGNAL(buttonSend(DBusObject)), &sender, SLOT(RegisterAndListen(DBusObject)));
But it's not working and I get the following error:
QObject::connect: No such signal Button_QMLTYPE_29_QML_31::buttonSend(DBusObject) in ../QT Dbus enviar Objeto/sisc2/main.cpp:32
Is there a way to pass a custom parameter in a QML signal? Can I only use the base types like string and int? How can I reference my DBusOBject in QML so I can use it as a signal parameter?
Any tip will be very helpful.
Thanks.Hi @marcosbontempo,
The error means that thesignal
is not found inrect
object. You need to find the exact item which contains that signal.
Now on QML side, send the signal as usual as:buttonSend(db)
. Here theid
of that instance is passed.
Also I think you may need use pointer in signal connection:QObject::connect(rect, SIGNAL(buttonSend(DBusObject *)), &sender, SLOT(RegisterAndListen(DBusObject *)));
-
Hi @p3c0,
Thanks for answering! I found the item which contains the signal. It's working when I send it with strings, but still not working with my DBusObject. How do I have to declare the signal? Is the following code right?DBusObject { id: db author: "oi" } Button { signal buttonSend(DBusObject dbobject) objectName: "btnLogin" id: button1 x: 12 y: 39 text: qsTr("Send") onClicked: button1.buttonSend(db) }
I'm also having problems in the C++ code. I connected the QML signal with the C++ code as you said:
QObject::connect(rect, SIGNAL(buttonSend(DBusObject *)), &sender, SLOT(RegisterAndListen(DBusObject *)));
How to I have to write the class? I did like this:
Header:
public slots: void RegisterAndListen(const DBusObject object);
Function:
void send_dbus::RegisterAndListen(const DBusObject object) { ... }
Is this right?
Thanks!
-
Hi @p3c0,
Thanks for answering! I found the item which contains the signal. It's working when I send it with strings, but still not working with my DBusObject. How do I have to declare the signal? Is the following code right?DBusObject { id: db author: "oi" } Button { signal buttonSend(DBusObject dbobject) objectName: "btnLogin" id: button1 x: 12 y: 39 text: qsTr("Send") onClicked: button1.buttonSend(db) }
I'm also having problems in the C++ code. I connected the QML signal with the C++ code as you said:
QObject::connect(rect, SIGNAL(buttonSend(DBusObject *)), &sender, SLOT(RegisterAndListen(DBusObject *)));
How to I have to write the class? I did like this:
Header:
public slots: void RegisterAndListen(const DBusObject object);
Function:
void send_dbus::RegisterAndListen(const DBusObject object) { ... }
Is this right?
Thanks!
@marcosbontempo The signal declaration is correct.
The slot declaration and definition should use pointervoid RegisterAndListen(DBusObject *);
-
Thanks @p3c0 ! Now it's working like I wanted!