
Originally Posted by
amitahire
Hello again,
I am trying to make a simple application where when I click a button the count is displayed in the QLineEdit. But I cant get the signal going. I have read different documentations but for custom signal and slots everywhere I see I get a different account or method.
I am posting my files. Please help me understand the concept
click.h
#ifndef CLICK_H
#define CLICK_H
#include<QMainWindow>
#include<QLineEdit>
#include<QPushButton>
namespace Ui
{
class click_me;
}
{
Q_OBJECT
public:
signals:
void click1(int);
private slots:
void disp();
private:
Ui::click_me *ui;
private:
};
#endif
#ifndef CLICK_H
#define CLICK_H
#include<QMainWindow>
#include<QLineEdit>
#include<QPushButton>
namespace Ui
{
class click_me;
}
class click_me:public QMainWindow
{
Q_OBJECT
public:
click_me(QWidget *Parent=0);
signals:
void click1(int);
private slots:
void disp();
private:
Ui::click_me *ui;
private:
QPushButton *p1;
QLineEdit *l1;
};
#endif
To copy to clipboard, switch view to plain text mode
click.cpp
#include"click.h"
#include"ui_click.h"
int count=0;
{
ui->setupUi(this);
//int count=0;
connect(ui->p1,SIGNAL(click1(int)),ui->l1,SLOT(disp(int)));
}
void click_me::disp(int)
{
//emit click1(count);
count = count +1;
ui->l1->setText(s);
}
//int click_me::click1(int co)
//{
//
// emit click1();
//return co;
//}
#include"click.h"
#include"ui_click.h"
int count=0;
click_me::click_me(QWidget *parent):QMainWindow(parent),ui(new Ui::click_me)
{
ui->setupUi(this);
//int count=0;
connect(ui->p1,SIGNAL(click1(int)),ui->l1,SLOT(disp(int)));
}
void click_me::disp(int)
{
//emit click1(count);
count = count +1;
QString s=QString::number(count);
ui->l1->setText(s);
}
//int click_me::click1(int co)
//{
//
// emit click1();
//return co;
//}
To copy to clipboard, switch view to plain text mode
click.zip
I am just unable to understand how do I pass parameters in the signal and even if I am passing one.... How do I go about declaring, defining and passing them.
Clearing its a off day for me :-\
Hello guys -- thanks for your reply but I think you didnt get what I was asking for and also my code last time was horrible.
Now check this is out
click_init.cpp
#include<QtGui>
#include"click.h"
int main(int argc,char *argv[])
{
click_me w;
w.show();
return a.exec();
}
#include<QtGui>
#include"click.h"
int main(int argc,char *argv[])
{
QApplication a(argc,argv);
click_me w;
w.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
click.h
#ifndef CLICK_H
#define CLICK_H
#include<QMainWindow>
#include<QLineEdit>
#include<QPushButton>
namespace Ui
{
class click_me;
}
{
Q_OBJECT
public:
//{ count = 0; }
int value() const { return count;}
signals:
void click1(int val);
private slots:
void disp(int val);
private:
Ui::click_me *ui;
private:
//QPushButton *p1;
//QLineEdit *l1;
int count;
};
#endif // CLICK_H
#ifndef CLICK_H
#define CLICK_H
#include<QMainWindow>
#include<QLineEdit>
#include<QPushButton>
namespace Ui
{
class click_me;
}
class click_me:public QMainWindow
{
Q_OBJECT
public:
click_me(QWidget *parent=0);
//{ count = 0; }
int value() const { return count;}
signals:
void click1(int val);
private slots:
void disp(int val);
private:
Ui::click_me *ui;
private:
//QPushButton *p1;
//QLineEdit *l1;
int count;
};
#endif // CLICK_H
To copy to clipboard, switch view to plain text mode
click.cpp
#include"click.h"
#include"ui_click.h"
//int count=0;
{
ui->setupUi(this);
count=0;
connect(this,SIGNAL(click1(int)),this,SLOT(disp(int)));
ui->l1->setText("0");
}
void click_me::disp(int val)
{
//if (val != count) {
count = val+1;
ui->l1->setText(s);
emit click1(count);
//}
}
#include"click.h"
#include"ui_click.h"
//int count=0;
click_me::click_me(QWidget *parent):QMainWindow(parent),ui(new Ui::click_me)
{
ui->setupUi(this);
count=0;
connect(this,SIGNAL(click1(int)),this,SLOT(disp(int)));
ui->l1->setText("0");
}
void click_me::disp(int val)
{
//if (val != count) {
count = val+1;
QString s=QString::number(count);
ui->l1->setText(s);
emit click1(count);
//}
}
To copy to clipboard, switch view to plain text mode
Now this works in the Creatoe but the slots just doesnt work. I am trying to increment and keep the updated value in textbox.
Please can you check whether the signal and slots are defined properly?
And whether my logic is correct, if not please explain it to me. Thanks
Bookmarks