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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T21:44:08+00:00 2026-05-19T21:44:08+00:00

I know this question has been asked a few time, (http://stackoverflow.com/questions/4436511/display-a-form-in-qt) I am trying

  • 0

I know this question has been asked a few time, (http://stackoverflow.com/questions/4436511/display-a-form-in-qt)

I am trying to open an existing form in my Qt C++ project.
it needs to be a subform instead of QDialog box.

both forms have a .ui, .h and .cpp file with them.

in my mwindowtest.cpp I have

//this is used to handle the button click to open the new form
connect(btnConnect, SIGNAL(click()), this, SLOT(openNewWindow()));

for function is:

void mWindowTest::openNewWindow(){

   mForm = new dialog (this);
   mForm->show();

}

in my mwindowtest.cpp I have:

#include <dialog.h>  //second form
class dialog;

I’m now getting the error mForm was not declared in this scope.
but I am not sure what to declare mForm as in my Header file.

any tips would be greatly appreciated.

Thanks

  • 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-19T21:44:08+00:00Added an answer on May 19, 2026 at 9:44 pm

    In your example you will have memory leak since each time button btnConnect is clicked you will reallocate memory for your form, without deleting the previous first.

    Concerning your problem, we need to know how is declare dialog in dialog.h to be able to really help you.
    In your mywindowtest.cpp you have included the file and redefined the class. Try to put

    class dialog
    

    in your hpp file and

    #include <dialog.h>
    

    in your cpp file.

    Hope that helps

    Edit:

    In your slot:

    delete mForm;
    mForm = new dialog();
    dialog->show();
    

    It’s the minimum to avoid memory leaks; And don’t forget to delete mForm in MyWindowTest destructor too if not null;

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

Sidebar

Related Questions

I know this kind of question has been asked a few times, but alot
I know this question has been asked quite a few times, however, I have
I know this question has been asked here a few times before. But i
I know this question has been asked many times, and I've searched stackoverflow and
I know this questions has been asked a few times here. But these seem
I know this question has been asked a few times. I understand how to
I know this question has been asked few times over SO but none of
I know this question has been asked a few times and in a few
I know this question has been asked a few times in various context, but
I know this question has been asked a few other times but I have

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.