Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. lambda expression capture
Qt 6.11 is out! See what's new in the release blog

lambda expression capture

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 1.6k 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.
  • QT-static-prgmQ Offline
    QT-static-prgmQ Offline
    QT-static-prgm
    wrote on last edited by
    #1

    Hi,

    is there a way to do this??

    connect(this, &MainWindow::loadFile, [viewer](QString value) {viewer->m_dataEngine->loadFile(value); });
    

    I'm in the MainWindow class and want to connect the loadFile signal from MainWindow with the loadFile function from GeometryEngine that is member of viewer.

    I thought i could make a lambda expression in viewer, but viewer does not hold an instance of MainWindow. So i hoped that there is a way to make it from MainWindow.

    jsulmJ 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      The clean way here would be to add a slot to your viewer class that will call whatever needed. The internals of that viewer class is of no concern to MainWindow.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • QT-static-prgmQ QT-static-prgm

        Hi,

        is there a way to do this??

        connect(this, &MainWindow::loadFile, [viewer](QString value) {viewer->m_dataEngine->loadFile(value); });
        

        I'm in the MainWindow class and want to connect the loadFile signal from MainWindow with the loadFile function from GeometryEngine that is member of viewer.

        I thought i could make a lambda expression in viewer, but viewer does not hold an instance of MainWindow. So i hoped that there is a way to make it from MainWindow.

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @QT-static-prgm Did you try it?
        If viewer is a member variable of MainWindow you can do it like this:

        connect(this, &MainWindow::loadFile, [this](QString value) {viewer->m_dataEngine->loadFile(value); });
        

        But as @SGaist said it would be better to implement a slot in Viewer.
        MainWindow should not care/know about Viewer internals like m_dataEngine.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        2

        • Login

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