PDA

View Full Version : no such signal QListBox::currentChanged()



jopie bakker
2nd March 2006, 16:05
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().


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();
};

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)
{
QObject::connect(
&quit, SIGNAL(clicked()),
&app, SLOT(quit())
);
QObject::connect(
&listbox, SIGNAL(currentChanged()),
this, SLOT(currentChanged())
);
QObject::connect(
&remove, SIGNAL(clicked()),
this, SLOT(removeClicked())
);
}


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();
};


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')


(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.

jacek
2nd March 2006, 16:13
QObject::connect: No such signal QListBox::currentChanged()
QObject::connect: (sender name: 'mylistbox')
QObject::connect: (receiver name: 'unnamed')
But there's no such signal indeed.

Try:
connect( &listbox, SIGNAL( currentChanged( QListBoxItem * ) ),
this, SLOT( currentChanged( QListBoxItem * ) ) );

jopie bakker
2nd March 2006, 16:17
Thanks! I had already tried to add the type to the SIGNAL() macro, but not to the SLOT() macro. So specifying the types for both the source and the destination does it.