Hello,
Linux - QT4
I'm trying to get to grips with signals and slots.
I am creating an array of subclassed QLineEdits
What I would like to do is connect the array index to my slot, so I no longer need to search thru' the QObject sender to find the array index.
I've done this in the past, but for the life of me can't remember how and can't find my notes, nor does several internet searches help.
Any suggestions will be appreciated.
Regards
{
for (int i = 0; i < 9; i++) {
e1[i] = new myLineEdit(g1);
e1[i]->setFont(font);
e1[i]->setGeometry(l1[i]->x() + l1[i]->width() + 4, l1[i]->y() -5, wDim[i], 25);
if (i >
4 && i <
9) QObject::connect(e1
[i
],
SIGNAL(mySignal0
(const int &)),
this,
SLOT(gpioType
(int)));
//only connect to 5, 6, 7 and 8
}
...
...
for (int i = 5; i < 9; i++) e1[i]->installEventFilter(this);
this->show();
}
settings::settings(const QString &path, QWidget *parent) : QDialog(parent)
{
for (int i = 0; i < 9; i++) {
e1[i] = new myLineEdit(g1);
e1[i]->setFont(font);
e1[i]->setGeometry(l1[i]->x() + l1[i]->width() + 4, l1[i]->y() -5, wDim[i], 25);
if (i > 4 && i < 9) QObject::connect(e1[i],SIGNAL(mySignal0(const int &)), this, SLOT(gpioType(int)));
//only connect to 5, 6, 7 and 8
}
...
...
for (int i = 5; i < 9; i++) e1[i]->installEventFilter(this);
this->show();
}
To copy to clipboard, switch view to plain text mode
void settings::gpioType(int i)
{
int num;
bool ok;
}
void settings::gpioType(int i)
{
QString test;
int num;
bool ok;
QObject *senderObj = sender();
}
To copy to clipboard, switch view to plain text mode
{
}
...
...
{
emit(focussed(false));
mySignal0(0);
}
myLineEdit::myLineEdit(QWidget *parent) : QLineEdit(parent)
{
}
...
...
void myLineEdit::focusOutEvent(QFocusEvent *e)
{
QLineEdit::focusOutEvent(e);
emit(focussed(false));
mySignal0(0);
}
To copy to clipboard, switch view to plain text mode
#ifndef MYLINEDIT_H
#define MYLINEDIT_H
#include <QLineEdit>
{
Q_OBJECT
public:
~myLineEdit();
signals:
void focussed(bool hasFocus);
void mySignal0(const int &i);
protected:
};
#endif // MYLINEDIT_H
#ifndef MYLINEDIT_H
#define MYLINEDIT_H
#include <QLineEdit>
class myLineEdit : public QLineEdit
{
Q_OBJECT
public:
myLineEdit(QWidget *parent = 0);
~myLineEdit();
signals:
void focussed(bool hasFocus);
void mySignal0(const int &i);
protected:
virtual void focusOutEvent(QFocusEvent *e);
};
#endif // MYLINEDIT_H
To copy to clipboard, switch view to plain text mode
Bookmarks