Get object, which have received signal

  • Hello. How to get object, which have received signal? Look at that code:
    @ for (var idx=0;idx<leftButtonSettings.length;idx++) {
    left_objects[idx] = component.createObject(left_menu_flick.contentItem, {
    "x": 0,
    "y": 0
    left_objects[idx].x = (left_menu_flick.width-left_objects[idx].width)/2;
    if (idx==0) {
    left_objects[idx].y = y_offset
    } else {
    left_objects[idx].y = left_objects[idx-1].y + left_objects[idx].height + y_offset
    left_objects[idx].name_text = leftButtonSettings[idx][0]
    left_objects[idx].desc_text = leftButtonSettings[idx][1]
    left_objects[idx].url = leftButtonSettings[idx][2]
    left_objects[idx].clicked.connect (function() {
    CMainWindow.tryLoadFromNetwork(object.desc_text) //What I must write here?
    in line "CMainWindow.tryLoadFromNetwork(object.desc_text)" I want to send text from field url to function CMainWindow.tryLoadFromNetwork which have written in C++. But how to get object in that case to get url field? Thanks

  • Just use "QObject::sender()":, if the code you posted above is inside a slot that received a signal and the object you're looking for is the sender of the signal.

    Then you could do something like this:
    if(qobject_cast<QWidget*>(QObject::sender())) // cast to the appropriate class here, QWidget is just as an example
    CMainWindow.tryLoadFromNetwork(qobject_cast<QWidget*>(QObject::sender()).desc_text) // cast to the appropriate class here, QWidget is just as an example

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.