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 752105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:44:34+00:00 2026-05-14T14:44:34+00:00

this is a simple OOP QT question. my app consists of main window (QMainWindow)

  • 0

this is a simple OOP QT question.
my app consists of main window (QMainWindow) and a table (QTableWidget).
in the main window i have arguments and variables which i would like to pass to the table class, and to access methods in main widnow class from the table class, how should i do it ?

mainwindow.h

class MainWindow : public QMainWindow {
    Q_OBJECT
private:
    int a;
    int b;
    Spreadsheet *spreadsheet;

public:
    void set_a(int);
    void set_b(int);

spreadsheet.h

class Spreadsheet : public QTableWidget {
    Q_OBJECT

public:
    Spreadsheet(QWidget *parent = 0);

atm i define Spreadsheet like this:

spreadsheet = new Spreadsheet(this);

and i’d like to access set_a() from spreadsheet.cpp…

  • 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-14T14:44:35+00:00Added an answer on May 14, 2026 at 2:44 pm

    You can use the parent() method in the Spreadsheet object to get a pointer to your MainWindow.

    For example,

    // spreadsheet.cpp
    MainWindow* mainWindow = (MainWindow*) this->parent();
    mainWindow->set_a(123);
    

    Of course, the parent object passed to Spreadsheet‘s constructor should be your MainWindow instance for this to work.

    However, you should seriously consider oscode’s suggestion, since it also points you towards creating a more Qt-like API.

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

Sidebar

Related Questions

New to OOP with Perl, and just had a quick question. I have this
this is more theoretical question. I have written simple chat with my friend. We
I'm quite new to PHP OOP and I have a question regarding a simple
I'm new to the OOP paradigm, so there's probably a simple explanation for this
Consider this simple example (which displays in red): echo -e \033[31mHello World\033[0m It displays
I hope this question takes a simple fix, and I am just missing something
I know that this is supposedly a super simple question, but I've been struggling
I'm new to OOP, so please bear with me if this is a simple
I'm sure this is a basic OOP question -- I'm designing a message-passing system
I'm building a simple php app using OOP that creates a CSV file based

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.