program compiles, but crashes when run. I've got:
// window.h
Q_OBJECT
public:
Window();
static Window* getInstance();
// window.cpp
Window* Window::getInstance() {
static Window *win=0;
if(!win) {
win = new Window();
}
return win;
}
return myLabel;
}
// model.h ...Coin3d scenegraph
#include <Inventor/*/*.h> //many
#include <QLabel> //was surprised I had to include this
#include "window.h"
// model.cpp
Window::getInstance()->getLabel()->setText("x");
// Window::getInstance(); //also crashes
// window.h
class Window : public QWidget {
Q_OBJECT
public:
Window();
static Window* getInstance();
QLabel *getLabel();
QLabel *myLabel;
// window.cpp
myLabel = new QLabel;
Window* Window::getInstance() {
static Window *win=0;
if(!win) {
win = new Window();
}
return win;
}
QLabel *Window::getLabel() {
return myLabel;
}
// model.h ...Coin3d scenegraph
#include <Inventor/*/*.h> //many
#include <QLabel> //was surprised I had to include this
#include "window.h"
// model.cpp
Window::getInstance()->getLabel()->setText("x");
// Window::getInstance(); //also crashes
To copy to clipboard, switch view to plain text mode
based on the last commented line: looks like I'm not employing the Singleton correctly.
Another question though: the call to update the QLabel value will happen ~25 times a second as the camera is moved. Is this still a good way to connect the camera X-value to the QLabel?
Bookmarks