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

  • SEARCH
  • Home
  • 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 4113148
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:17:12+00:00 2026-05-20T22:17:12+00:00

I wish to add items in a ListWidget, which is a private member of

  • 0

I wish to add items in a ListWidget, which is a private member of a class, through a friend function. Actually, i am trying this sample snippet to use friend function for more classes to update their ListWidgets from a single function.

I need guidance in using friend function in my case.

Kindly forgive my ignorance on the topic, any help is appreciated.

    class InBoxTab : public QWidget
    {
    Q_OBJECT

    public:
        InBoxTab(QWidget *parent = 0);
       // InBoxTab();
        ~InBoxTab();

    public slots:
        void hello();
        friend void adda(); // friend function
    private:
        QListWidget* listWidget1; //data member accessed by friend function
    };



    void adda()
    {
        InBoxTab I;

        I.listWidget1->insertItem(1,QString("added frm fn"));

        I.listWidget1->update();
    }


InBoxTab::InBoxTab(QWidget *parent) :
        QWidget(parent)
{
        listWidget1 = new QListWidget(this);

        QListWidgetItem* item = new QListWidgetItem("Item 1 added frm tab1 ");

        listWidget1->addItem(item);
        adda();   // Call to friend function

        QVBoxLayout* layout = new QVBoxLayout(this);
        layout->addWidget(listWidget1);
        this->setLayout(layout);
}
  • 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-05-20T22:17:13+00:00Added an answer on May 20, 2026 at 10:17 pm

    As far as I can see, the ‘adda’ function does not affect anything. It returns nothing, and only operates on ‘I’ which is deleted when ‘adda’ is finished.

    An example of how I believe you could use a friend function would be if you declared/defined ‘adda’ as:

    void adda(InBoxTab *I)
    {
            I->listWidget1->insertItem(1,QString("added frm fn"));
            I->listWidget1->update();
    }
    

    … Although in that particular case there is no reason not to make ‘adda’ a member of the InBoxTab instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list item: <li class=sortedli>Call Type</li> I wish to add two div's
If i wish to put items into a System.Collections.Generic.Dictionary , I can either Add
I am making an android application that needs to add items to a dynamic
I wish to dynamically extend my CxxTest Suite with additional test items, but am
I have a combo box (winform). This combo box has some items (eg. 1,2,3,4).
I wish to make views highlighted like items in a listview(I use linearlayout instead
In the Eclipse Project Explorer, I wish to add either a special icon or
I'm facing this weird issue with Scripting.Dictionary object in my VBA code. I wish
In this small, but full example, I am trying to recreate a dual list
I have a PHP generated form which consists of a list of items, each

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.