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 512 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.
  • BDC_PatrickB Offline
    BDC_PatrickB Offline
    BDC_Patrick
    wrote on 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?

    jsulmJ J.HilkJ 2 Replies Last reply
    0
    • BDC_PatrickB BDC_Patrick

      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?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on 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
      • BDC_PatrickB BDC_Patrick

        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.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on 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
        • BDC_PatrickB Offline
          BDC_PatrickB Offline
          BDC_Patrick
          wrote on 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

          • Login

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