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. Connect Signal with Argument via Lambda to Slot with Argument?

Connect Signal with Argument via Lambda to Slot with Argument?

Scheduled Pinned Locked Moved Unsolved General and Desktop
lambdaargumentsignal & slotcpp
4 Posts 3 Posters 507 Views
  • 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.
  • B Offline
    B Offline
    BDC_Patrick
    wrote on 2 Nov 2021, 10:34 last edited by
    #1

    Ok.. hi..

    Following Situation:
    I crated a QDialog with this Signals:

    signals:
        void created(QString _path);
        void aborted();
    

    Inside the Window, that calls this Dialog, i want to Connect a Slot:

    private slots:
        void _onOpenproject(QString _path);
    

    With the Dialogs Signal..

    My current call and Connect is this:

    void TGS_WindowProjectLibrary::_onNewProject() {
        TGS_Dialog_NewProject _newProj;
        connect(&_newProj,&TGS_Dialog_NewProject::created,this,[this]{ _onOpenproject();} );
    
        _newProj.exec();
    }
    

    Question now:
    How to connect the SIGNALs QString with the SLOTs?

    J J 2 Replies Last reply 2 Nov 2021, 10:36
    0
    • B BDC_Patrick
      2 Nov 2021, 10:34

      Ok.. hi..

      Following Situation:
      I crated a QDialog with this Signals:

      signals:
          void created(QString _path);
          void aborted();
      

      Inside the Window, that calls this Dialog, i want to Connect a Slot:

      private slots:
          void _onOpenproject(QString _path);
      

      With the Dialogs Signal..

      My current call and Connect is this:

      void TGS_WindowProjectLibrary::_onNewProject() {
          TGS_Dialog_NewProject _newProj;
          connect(&_newProj,&TGS_Dialog_NewProject::created,this,[this]{ _onOpenproject();} );
      
          _newProj.exec();
      }
      

      Question now:
      How to connect the SIGNALs QString with the SLOTs?

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 2 Nov 2021, 10:36 last edited by
      #2

      @BDC_Patrick said in Connect Signal with Argument via Lambda to Slot with Argument?:

      How to connect the SIGNALs QString with the SLOTs?

      connect(&_newProj,&TGS_Dialog_NewProject::created,this,[this](QString str){ _onOpenproject(str);} );
      

      But why don't you connect the signal directly to the slot?

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

      1 Reply Last reply
      3
      • B BDC_Patrick
        2 Nov 2021, 10:34

        Ok.. hi..

        Following Situation:
        I crated a QDialog with this Signals:

        signals:
            void created(QString _path);
            void aborted();
        

        Inside the Window, that calls this Dialog, i want to Connect a Slot:

        private slots:
            void _onOpenproject(QString _path);
        

        With the Dialogs Signal..

        My current call and Connect is this:

        void TGS_WindowProjectLibrary::_onNewProject() {
            TGS_Dialog_NewProject _newProj;
            connect(&_newProj,&TGS_Dialog_NewProject::created,this,[this]{ _onOpenproject();} );
        
            _newProj.exec();
        }
        

        Question now:
        How to connect the SIGNALs QString with the SLOTs?

        J Offline
        J Offline
        J.Hilk
        Moderators
        wrote on 2 Nov 2021, 10:37 last edited by
        #3

        @BDC_Patrick
        no need for a lambda here:

        connect(&_newProj,&TGS_Dialog_NewProject::created,this, &TGS_WindowProjectLibrary::_onOpenproject);
        

        if you insist on using a lambda;

        connect(&_newProj,&TGS_Dialog_NewProject::created,this,[this](QString argument)->void{ _onOpenproject(argument);} );
        

        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        1 Reply Last reply
        3
        • B Offline
          B Offline
          BDC_Patrick
          wrote on 2 Nov 2021, 10:41 last edited by
          #4

          @jsulm & @J-Hilk

          Thank you so much. You´re my Heroes :D

          Everyday something new to learn :)

          1 Reply Last reply
          0

          4/4

          2 Nov 2021, 10:41

          • Login

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