hersheyzombie
3rd September 2010, 22:29
I have a mainwindow with a textedit widget.
I would like my mainwindow to have an instance of a custom class, called "scene" that has signals and slots connected to ui items, like my textedit widget.
I create my scene as follows:
scene.h
class scene : public QObject
{
Q_OBJECT
public:
scene();
signals:
void setImName(const QString&);
};
scene.cpp
#include "scene.h"
scene::scene() : QObject()
{
emit setImName( tr("hello") );
}
In my mainwindow code, I declare a scene called "myScene" and attempt to connect it to the slot for my textedit widget. This compiles without error but results in a memory access related crash when I run my program. Commenting the "connect" line allows my program to run (but of course not behave as desired).
connect(myScene, SIGNAL(setImName(const QString&)), ui->textEdit1, SLOT(setText(QString)));
Any ideas what I am doing wrong?
I would appreciate any example where someone has created their own QObject with signals and slots that connect to ui widgets...
I would like my mainwindow to have an instance of a custom class, called "scene" that has signals and slots connected to ui items, like my textedit widget.
I create my scene as follows:
scene.h
class scene : public QObject
{
Q_OBJECT
public:
scene();
signals:
void setImName(const QString&);
};
scene.cpp
#include "scene.h"
scene::scene() : QObject()
{
emit setImName( tr("hello") );
}
In my mainwindow code, I declare a scene called "myScene" and attempt to connect it to the slot for my textedit widget. This compiles without error but results in a memory access related crash when I run my program. Commenting the "connect" line allows my program to run (but of course not behave as desired).
connect(myScene, SIGNAL(setImName(const QString&)), ui->textEdit1, SLOT(setText(QString)));
Any ideas what I am doing wrong?
I would appreciate any example where someone has created their own QObject with signals and slots that connect to ui widgets...