Hi, I've been struggling for a few hours with this error now so I joined these boards. I would be most obliged if you could help me figure this out. I'm posting this in the newbie forum because this is my first Qt program and it seems I'm making some silly mistake.
I have a MainForm class, which has various QWidgets as members and a DotListBox class, which inherits from QListBox. When I try to connect the DotListBox::currentChanged() signal to the MainForm::currentChanged slot, I get a "no such signal error" at run-time.
This is mainform.h. The program's main function just constructs this object and calls MainForm::execute().
{
Q_OBJECT
private:
Points points;
QHBox hbox;
QVBox vbox;
DotListBox listbox;
DotWidget dots;
public slots:
void currentChanged(QListBoxItem *);
void removeClicked();
public:
MainForm(int argc, char *argv[]);
~MainForm();
int Execute();
};
class MainForm : public QObject
{
Q_OBJECT
private:
Points points;
QApplication app;
QHBox hbox;
QVBox vbox;
DotListBox listbox;
QPushButton remove;
QPushButton quit;
DotWidget dots;
public slots:
void currentChanged(QListBoxItem *);
void removeClicked();
public:
MainForm(int argc, char *argv[]);
~MainForm();
int Execute();
};
To copy to clipboard, switch view to plain text mode
This is the constructor of MainForm:
MainForm::MainForm(int argc, char *argv[])
: points()
, app(argc, argv)
, hbox(0)
, vbox(&hbox)
, listbox(&vbox, &points)
, remove("&Remove", &vbox)
, quit("&Quit", &vbox)
, dots(&hbox, &points)
{
&quit, SIGNAL(clicked()),
&app, SLOT(quit())
);
&listbox, SIGNAL(currentChanged()),
this, SLOT(currentChanged())
);
&remove, SIGNAL(clicked()),
this, SLOT(removeClicked())
);
}
MainForm::MainForm(int argc, char *argv[])
: points()
, app(argc, argv)
, hbox(0)
, vbox(&hbox)
, listbox(&vbox, &points)
, remove("&Remove", &vbox)
, quit("&Quit", &vbox)
, dots(&hbox, &points)
{
QObject::connect(
&quit, SIGNAL(clicked()),
&app, SLOT(quit())
);
QObject::connect(
&listbox, SIGNAL(currentChanged()),
this, SLOT(currentChanged())
);
QObject::connect(
&remove, SIGNAL(clicked()),
this, SLOT(removeClicked())
);
}
To copy to clipboard, switch view to plain text mode
The signals related to the quit and remove buttons connect fine to their slots.
This is the dotlistbox.h header file:
class DotListBox : public QListBox, public Observer
{
private:
Points *points;
public:
DotListBox
(QWidget *parent, Points
*p
= NULL);
virtual ~DotListBox();
void Update();
};
class DotListBox : public QListBox, public Observer
{
private:
Points *points;
public:
DotListBox(QWidget *parent, Points *p = NULL);
virtual ~DotListBox();
void Update();
};
To copy to clipboard, switch view to plain text mode
As you can see, it also inherits from an Observer class, of which it implements the Update() function. The problem is that I can't connect the currentChanged() signal of my derived listbox to the currentChanged() slot of MainForm.
./dots
Xlib: extension "XInputExtension" missing on display ":1.0".
Failed to get list of devices
QObject::connect: No such
signal QListBox
::currentChanged() QObject::connect: (sender name
: 'mylistbox') QObject::connect: (receiver name
: 'unnamed')
./dots
Xlib: extension "XInputExtension" missing on display ":1.0".
Failed to get list of devices
QObject::connect: No such signal QListBox::currentChanged()
QObject::connect: (sender name: 'mylistbox')
QObject::connect: (receiver name: 'unnamed')
To copy to clipboard, switch view to plain text mode
(The Xlib error seems to be FreeBSD specific, I'm blissfully ignoring that for the moment.)
My hunch is that the problem is that DotListBox is derived from QListBox and that the signal slots don't get inherited, but I'm not sure.
Thanks in advance for any help.
Bookmarks