PDA

View Full Version : signals and slots problem



sonuani
27th February 2008, 06:06
hi,
If my lineedit control changes then a message has to be displayed.
I have dont like this.


public slots:
OnChangelineedit();

connect(lineedit1, SIGNAL(cursorPositionChanged(0,1)),
this, SLOT(OnChangelineedit()));


But i am getting error"

Object::connect: No such signal QLineEdit::cursorPositionChanged(0,1)
Object::connect: (sender name: 'lineedit1)
Object::connect: (receiver name: 'dialog')".
What is wrong with my code.

jpn
27th February 2008, 07:45
I recommend reading about signals and slots (http://doc.trolltech.com/4.3/signalsandslots.html). You can't put parameter names or values but only parameter types in connect statement.

topher
27th February 2008, 07:48
How about this...


connect(lineedit1, SIGNAL(cursorPositionChanged(int, int)), this, SLOT(OnChangelineedit()));

cyan21
11th March 2008, 10:11
Hello,

I'm using Eclipse and QT4 and I get exactly the same problem but the previous post doesn't really help very much.



#ifndef TEST_QT_H
#define TEST_QT_H

#include <QtGui/QWidget>
#include "ui_test_qt.h"

class test_qt : public QWidget
{
Q_OBJECT

public:
test_qt(QWidget *parent = 0);
~test_qt();

private:
Ui::test_qtClass ui;

public slots:
void test();
};

#endif // TEST_QT_H




#include "test_qt.h"

test_qt::test_qt(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
connect(ui.pButton, SIGNAL(clicked()), ui.label, SLOT(test()));
}

test_qt::~test_qt()
{

}

void test_qt::test()
{
ui.label->setText("GO");
}



I get this error:



Object::connect: No such slot QLabel::test()
Object::connect: (sender name: 'pButton')
Object::connect: (receiver name: 'label')


can somebody help me on this ?
thanks

jpn
11th March 2008, 10:18
You are passing an incorrect receiver to the connect statement. QLabel does not have such slot as "test()". The test_qt class written by you does. So you should not pass "ui.label" but something else to the connect statement.

windsword
25th November 2008, 21:15
Hell I have a similar problem, the error message I get is:
Object::connect: No such slot QWidget::adminstart()

If I add Q_OBJECT to my class, I get the following error msg when I type "make"
ndefined symbols:
"vtable for harpWin", referenced from:
__ZTV7harpWin$non_lazy_ptr in harpwin.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

Here is my code (all in one file ):


class harpWin : public QWidget
{
Q_OBJECT

public:
harpWin(QWidget *parent = 0);
~harpWin();

QGraphicsView *graphicsView;
QPushButton *adminButton;
QPushButton *measureButton;
QPushButton *viewButton;
QPushButton *quitButton;
QVBoxLayout *vboxLayout;
QHBoxLayout *hboxLayout;

public slots:
void adminstart();
};

harpWin::harpWin( QWidget *parent)
: QWidget(parent)
{
setWindowTitle("Harp Win0");
vboxLayout = new QVBoxLayout();
hboxLayout = new QHBoxLayout();

graphicsView = new QGraphicsView(this);
adminButton = new QPushButton("Admin", this);
adminButton->setDefault(true);
measureButton = new QPushButton("Measure", this);
viewButton = new QPushButton("View", this);
quitButton = new QPushButton("&Quit",this);

vboxLayout->addWidget(adminButton);//, 1, Qt::AlignRight);
vboxLayout->addWidget(measureButton);
vboxLayout->addWidget(viewButton);
vboxLayout->addWidget(quitButton);

hboxLayout->addWidget(graphicsView, 1, Qt::AlignLeft);
hboxLayout->addLayout(vboxLayout);
setLayout(hboxLayout);

QObject::connect(quitButton, SIGNAL(clicked()), qApp, SLOT(quit()));
connect(adminButton, SIGNAL(clicked()), this, SLOT( adminstart() ));
QObject::connect(viewButton, SIGNAL(clicked()), qApp, SLOT(quit()));
QObject::connect(measureButton, SIGNAL(clicked()), qApp, SLOT(quit()));
}

harpWin::~harpWin()
{

}

void harpWin::adminstart()
{
QString str = "\n clicked button\n";
qDebug() << str;
}


int main(int argc, char *argv[])
{
QApplication app(argc, argv);

harpWin introWindow;

//introWindow.setWindowTitle("Absolute");
introWindow.show();

return app.exec();
}

jacek
26th November 2008, 18:00
If I add Q_OBJECT to my class, I get the following error msg when I type "make"
Do you use qmake? If yes, then you have to re-run it after you add Q_OBJECT macro.