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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:15:36+00:00 2026-05-23T04:15:36+00:00

This seems like it should be a simple question. I have two QSpinBoxes in

  • 0

This seems like it should be a simple question. I have two QSpinBoxes in my MainWindow, with a push button beside them. The user first selects the dimensions of an array of checkboxes using these spin boxes, then clicks the push button. This pops up a new window with the array of checkboxes in it. The problem I am having though is that when I try to get the value of the spinboxes in my popup window’s code, I get a compiler error because these buttons are private. Here is the code:

void DomainGeneration::createBoxes()
{
    int x_dim = MainWindow::ui->xDim->value();
    int y_dim = MainWindow::ui->yDim->value();
......the code......
}

Compiler errors:

‘Ui::MainWindow* MainWindow::ui’ is
private within this context

and

object missing in reference to
‘MainWindow::ui’ from this location

So my question is, how do I access these objects from a different window?

  • 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-23T04:15:37+00:00Added an answer on May 23, 2026 at 4:15 am

    You have two problems:

    1. MainWindow::ui is private
    2. MainWindow::ui is not static, you need an actual instance of a MainWindow to reach it

    To solve one, you usually create accessor methods in the MainWindow (or whatever class it is that needs to export some of its state).

    To solve two, you need a pointer to your MainWindow instance to call these accessors on.

    In your MainWindow class, define something like:

    int getXDim() const { return ui->xDim->value(); }
    

    And to get the pointer to your main window, either pass it in to your DomainGeneration’s constructor, or into that createBoxes() method, depending on how/where those are called and whether or not you’ll need that pointer elsewhere in that class.

    Something like:

    void DomainGeneration::createBoxes(MainWindow const* main)
    {
      int x_dim = main->getXDim();
      ...
    }
    

    (Or just pass the dimensions to that methods, obviously.)

    (None of this is Qt specific. This is plain C++.)

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

Sidebar

Related Questions

Anybody have a slicker way to do this? Seems like it should be easier
This seems like a pretty softball question, but I always have a hard time
This seems like a simple question, but I can't find it with the Stack
It seems like this should be straightforward but I'm boggling. I've got my listview
It seems like there should be something shorter than this: private string LoadFromFile(string path)
First check out this code. I seems like it should work for me, but
This seems like a very simple and a very common problem. The simplest example
This seems like a silly question but I would really like your comments and
This seems like perhaps a naive question, but I got into a discussion with
Simple Java generics question: I have two classes - one of which uses generics

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.