Reputation: 15
I have a class :
class gameClientInteraction : public QMainWindow
with, in the .h :
private :
QTextEdit* console;
my constructor is like this :
gameClientInteraction::gameClientInteraction()
{
// Menus
QMenu *menuFichier = menuBar()->addMenu("&Jeu");
QAction *actionQuitter = new QAction("&Quitter", this);
menuFichier->addAction(actionQuitter);
connect(actionQuitter, SIGNAL(triggered()), qApp, SLOT(quit()));
// View
QGraphicsView *theGraphicsView = new QGraphicsView(this);
theGraphicsView->setFixedSize(605,605);
QTextEdit* console = new QTextEdit(this);
console->setGeometry(0,625,600,100);
console->setReadOnly(true);
console->append("Bienvenue !");
setCentralWidget(theGraphicsView);
//Scene
theGraphicsView->setScene(m.afficheMap());//afficheMap give me a QGraphicsScene*
}
I have this function that crash my program when I launch it (it 's okay when I comment the instruction).
void gameClientInteraction::msgConsole(QString msg){
console->append(msg);
}
So why is it crashing with this instruction?
Upvotes: 0
Views: 100
Reputation: 7777
You've hidden the class member variable console
in your constructor by declaring a local pointer with the same name. In other words, this:
QTextEdit* console = new QTextEdit(this);
should be this:
console = new QTextEdit(this);
As an alternative, consider using an initialization list:
gameClientInteraction::gameClientInteraction() : console(new QTextEdit(this))
{
// constructor code goes here
console->setGeometry(0,625,600,100);
console->setReadOnly(true);
console->append("Bienvenue !");
}
Upvotes: 1