PDA

View Full Version : not emiting signal



bisz
2nd October 2007, 20:53
Hi, I'm trying to make a simplest program people have ever seen...

Here it is main.cpp:

#include <QApplication>
#include <QDialog>
#include "chala.h"

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

Ui::chala ui;
QDialog *dialog = new QDialog;
ui.setupUi(dialog);
dialog->show();
return app.exec();
}

chala.h:


#ifndef CHALA_H
#define CHALA_H
#include <QDialog>
#include "ui_chala.h"

class chala : public QDialog, public Ui::chala
{
Q_OBJECT

public:
chala(QWidget *parent = 0);

public slots:
void srutututu();
void majtki();

};
#endif



and chala.cpp :


#include <QtGui>

#include "chala.h"

chala::chala(QWidget *parent)
: QDialog(parent)
{
setupUi(this);

connect(pushButton, SIGNAL(clicked()), this, SLOT(srutututu()));
connect(pushButton_2, SIGNAL(clicked()), this, SLOT(majtki()));

}
void chala::srutututu()
{
qDebug() << "slot 1";
lineEdit->setText("new content");
}
void chala::majtki()
{
label_2->setText("elo 6700");
}


and 'ive done a simpliest window in designer with 4 pushbuttons lineEdit and label.... :

piece of ui_chala.cpp

QObject::connect(pushButton, SIGNAL(clicked()), lineEdit, SLOT(hide()));
QObject::connect(pushButton_2, SIGNAL(clicked()), lineEdit, SLOT(show()));

When i'm creating signal slot show/hide in designer everything works fine!
But when i'm trying to use my own slot(srutututu() and majtki()) actually nothing happens..
in my opinion signal is even not emited. So what am i doing wrong ?

jacek
2nd October 2007, 21:02
You don't instantiate that class in main(). It should be:

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

chala dlg;
dlg.show();

return app.exec();
}

wysota
2nd October 2007, 21:25
Yes... "majtki" is a very good slot name, I'll have to remember that one...

sunil.thaha
3rd October 2007, 07:15
me too... :D

bisz
3rd October 2007, 07:49
it should be 'srutututu majtki z drutu' ;)
thanks for your help, it works now :)