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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:19:03+00:00 2026-06-04T07:19:03+00:00

I am using Qt to create a window and I have the following code

  • 0

I am using Qt to create a window and I have the following code (this is somewhat in pseudo-code):

class MyInterface {
    virtual void doupdate() = 0;
}

class InterfaceHandler {
    InterfaceHandler(MyInterface *i) {
      the_int = i;

      start_thread(&mainloop);
    }

    void mainloop() {
        while(1) the_int->doupdate();
    }

    MyInterface *the_int;
}

class console : public QMainWindow, public MyInterface {
    console() {
            InterfaceHandler x(this);
    }

    void doupdate() {
        //code to modify the gui
    }
} 

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    console w(argc, argv);
    w.show();
    return a.exec();
}

My issue is that when the_int->doupdate() is called in mainloop(), the reference to the_int is wrong. I think this has to do with the fact that console inherits QMainWindow, but I am not sure what the solution is.

MyInterface doesn’t always get inherited by a QObject. I’ve tried to split the doupdate() from console into another class which gets passed the reference to console in the constructor, but get the same result.

Any ideas?

  • 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-06-04T07:19:04+00:00Added an answer on June 4, 2026 at 7:19 am

    Assuming your “pseudo-code” is close enough to your real code, the following is the problem:

    console() {
      InterfaceHandler x(this);
    }
    

    Once the constructor is done, x, being a local (automatic) variable, gets destroyed. The InterfaceHandler instance you created no longer exists once the constructor returns.

    You need to keep x as a member variable of that class, or create and store it from somewhere else. (But keeping it as a member makes sense since the lifetimes of the objects are tied.) You also need to be very careful with that thread, it needs to be stopped before console is destroyed.

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

Sidebar

Related Questions

I have following code public partial class MainWindow : Window { public MainWindow() {
I'm using the following code to create a modal (this is coffeescript) contents =
While developing a firefox extension, I create a wizard window from overlay.js using: this.wizard
I'm creating an application with its main window hidden by using the following code:
I have the following code. Class KochSnowflakesMenu is a grid JPanel with three buttons.
I have created a modal window using the Prototype JavaScript framework and the following
I have this code void drawText2(Canvas c) { DisplayMetrics metrics = new DisplayMetrics(); Display
I created a window using the design panel in JFrame, it didn't have any
I'm using CreateWindowEx() function to create an EDIT window, i.e. where a user can
I'm using Lightwindow v2 in a Symfony project to create a modal window (

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.