Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9243981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:55:29+00:00 2026-06-18T08:55:29+00:00

This is a rather unusual problem – but a problem nonetheless. I have a

  • 0

This is a rather unusual problem – but a problem nonetheless. I have a function that accepts a lambda as a parameter and then passes it on to QObject::connect:

template<typename Functor>
void MyClass::doSomething(Functor f)
{
    connect(network_reply, &QNetworkReply::finished, f);
    //...
}

A sample invocation of MyClass::doSomething might look like this:

doSomething([]()
{
    // how do I get access to the sender???
});

As you can tell by my comment, there is no way to access QObject::sender to get a pointer to the QObject that emitted the signal. Because the class emitting the signal is not in the scope that the lambda is being created in, there is no way of referencing it inside the lambda.

What options do I have?


Edit: I tried using Andy’s suggestion (std::bind) but I end up getting one of those template errors that are nearly impossible to understand:

http://paste.ubuntu.com/1614425/

Excerpt:

decltype cannot resolve address of overloaded function

…and it points to the QObject::connect call.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T08:55:30+00:00Added an answer on June 18, 2026 at 8:55 am

    If I understood your requirements correctly, you can first let your lambda functor accept an argument of the appropriate type (passing by reference here, so take care of lifetime issues):

    doSomething([](QNetworkReply* p)
    {
        // Here you have the sender referenced by p
    });
    

    Then, your doSomething() template function could use std::bind() to make sure your lambda will be invoked with the appropriate object as its argument:

    template<typename Functor>
    void MyClass::doSomething(Functor f)
    {
        connect(network_reply, &QNetworkReply::finished, bind(f, network_reply));
        //...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have rather unusual problem. It is hard to explain, so this is address
This is a rather unusual question but here's the issue: I have a WPF
This may be rather noobish but I'm gonna ask anyhow. I have a class
I have a rather unusual problem, and it is hurting my brain. Problem: Given
I have this rather simple SQL query, but it takes almost a minute to
I have a rather unusual layout that I'm trying to make a reality. There
I have a rather unusual problem... we are tasked with mapping a series of
Sorry for this rather basic question, but I have to get some sort of
Evening folks!! Stuck with this rather dull problem. I have deployed my website on
Consider this (rather pointless) javascript code: function make_closure() { var x = 123, y

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.