FLTK logo

[fltk/fltk] Fl::run returns immediately when Fl_Window is wrapped in a PIMPL class (#275)

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.issues  ]
 
Previous Message ]New Message | Reply ]Next Message ]

[fltk/fltk] Fl::run returns immediately when Fl_Window is wrapped in a PIMPL class (#275) Neur1n Sep 27, 2021  
 

I apologize that I don't know how to descript it in short, so let's begin with a working example:

#include <FL/Fl.H>
#inlucde <FL/Fl_Window.H>

class App
{
public:
  App(int w, int h, const char *title)
  {
    this->m_win = new Fl_window(w, h, title);
    this->m_win->show();
  }

  ~App()
  {
    if (this->m_win)
    {
      delete this->m_win;
      this->m_win = nullptr;
    }
  }
private:
  Fl_Window *m_win;
};

int main()
{
  App app(400, 300, "APP");
  return Fl::run();
}

The above snippet works properly and show an empty window when it runs, but when I turned it into PIMPL (see below), the window flashes and main returns 0 almost immediately:

In app.h file:

class AppImpl;

class App
{
public:
  App(int w, int h, const char *title);
  ~App();
private:
  AppImpl *m_impl;
};

In app.cpp file:

#include "app.h"

class AppImpl
{
public:
  AppImpl(int w, int h, const char *title)
  {
    this->m_win = new Fl_window(w, h, title);
    this->m_win->show();
  }

  ~AppImpl()
  {
    if (this->m_win)
    {
      delete this->m_win;
      this->m_win = nullptr;
    }
  }

private:
    Fl_Window *m_win;
};


int main()
{
  App app(400, 300, "APP");
  return Fl::run();
}

Therefore the problem is, how to make the PIMPL code work? I've read the multithreading part of the documentation, but I'm not sure if my code is related.

Any help is much appreciated.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.

Direct Link to Message ]
 
     
Previous Message ]New Message | Reply ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.