Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Get object, which have received signal
Qt 6.11 is out! See what's new in the release blog

Get object, which have received signal

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 1.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rus_phantom
    wrote on last edited by
    #1

    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?
    showLoadingStatic();
    })
    }@
    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

    1 Reply Last reply
    0
    • K Offline
      K Offline
      KA51O
      wrote on last edited by
      #2

      Just use "QObject::sender()":http://qt-project.org/doc/qt-4.8/qobject.html#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
      }
      @

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved