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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:50:17+00:00 2026-05-25T10:50:17+00:00

So i have a program that uses a subclass of QMainWindow for QMdiArea widgets.

  • 0

So i have a program that uses a subclass of QMainWindow for QMdiArea widgets. I’m only doing this because QDockWidgets can only be used in a QMainWindow (and my subclass needed dock widgets).

I was testing my class’s serialization for saving purposes and my pointer wasn’t correct. Here is the code

    if (ui->mdiMain->subWindowList().length() > 0)
    {
        QString path = QFileDialog::getSaveFileName(this, "Save Build Order", "" ,"*.cbo");

        if (path > 0)
        {
            QFile file(path, this);
            if (file.open(QFile::WriteOnly) == true)
            {
                QWidget* widget = reinterpret_cast<QWidget*>(ui->mdiMain->activeSubWindow());
                WidgetBuildOrder* widgetBuildOrder = reinterpret_cast<WidgetBuildOrder*>(widget);

                QDataStream stream(&file);
                stream << widgetBuildOrder;

                file.close();
                ui->statusBar->showMessage("Save Successful.", 5000);
            }
        }

    }
}

WidgetBuildOrder is a subclass of MainWindow.

so my thought was that I could keep casting the pointer to what it actually is. When I created the MDI area, i passed a new WidgetBuildOrder. Is there a way to do this?

To Clarify, after the casting I do get a pointer its just pointing to garbage. Not the values set in the WidgetBuildOrder I actually have open.

Any help will be appreciated,

Thanks,

Jec

  • 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-25T10:50:17+00:00Added an answer on May 25, 2026 at 10:50 am

    QMdiArea::activeSubWindow returns a QMdiSubWindow*, or 0 it the QMdiArea doesn’t have the focus.

    As you can’t possibly have a class that inherits from QMainWindow and QMdiSubWindow, what you want is to get the widget inside the current sub-window:

    QMdiSubWindow *subWindow = ui->mdiMain->currentSubWindow();
    WidgetBuildOrder* widgetBuildOrder = 
        static_cast<WidgetBuildOrder*>(subwindow->widget());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to have a program that uses multiple forks. I used this
I have written a program that uses qhttp to get a webpage. This works
I have a program that uses the GPU for performing certain computations. I can
I have a C# program that uses a class from another assembly, and this
Hi I have this program that I am writing that uses the struct below.
I have a python program that uses a custom-built DLL. This DLL crashes due
I have a program that uses the mt19937 random number generator from boost::random. I
I have a program that uses JAMA and need to test is a matrix
I have a program that uses pthread library to do the matrix multiplication of
I have a program that uses: ThreadPool.QueueUserWorkItem(new WaitCallback(FireAttackProc), fireResult); On Windows7 and Vista it

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.