Hi all !
Well, I am working for my first time in life with Qt libs and I have a few problems.
First, I want to make a QApplication very simple to practise signal/slots functionality.
The idea is: A QFrame with 1 Qlabel, 1QPushbutton and 1 QLineEdit. When you write something in the line edit, it is printed ( char by char) on the label. The button is used to exit ( close()). Quite easy.
Second exercise: the same thing but now, if you write something, it is displayed on the label with capital letters the even chars and normal letters the odd.
So I need to specialise QLabel with a new class that inherits from it, with a new slot setText(const QString &).
Here is my code:
#include <QString>
#include <QObject>
#include <QLabel>
class QLabelMM : public QLabel {
Q_OBJECT
public:
LabelMM();
public slots:
void setTextMM( const QString &text){
//const QString str = text;
for(int i = 0; i < text.length(); i++)
{
if(i%2 == 0) text.data()[i] = text.data()[i] +20;
}
}
}
Don't bother about macros like Q_OBJECT, qmake takes care of it.
And my errors: lab1.cpp:23: error: expected unqualified-id at end of input (line 23 is the "}" that closes the slot
Any thoughts that what is failing?
Another thing is that I don't think that is correct the way I pass from capitals to normals (text.data()[i] +20) but that is another question that I hope to resolve on my own :p!
Well, I am working for my first time in life with Qt libs and I have a few problems.
First, I want to make a QApplication very simple to practise signal/slots functionality.
The idea is: A QFrame with 1 Qlabel, 1QPushbutton and 1 QLineEdit. When you write something in the line edit, it is printed ( char by char) on the label. The button is used to exit ( close()). Quite easy.
Second exercise: the same thing but now, if you write something, it is displayed on the label with capital letters the even chars and normal letters the odd.
So I need to specialise QLabel with a new class that inherits from it, with a new slot setText(const QString &).
Here is my code:
#include <QString>
#include <QObject>
#include <QLabel>
class QLabelMM : public QLabel {
Q_OBJECT
public:
LabelMM();
public slots:
void setTextMM( const QString &text){
//const QString str = text;
for(int i = 0; i < text.length(); i++)
{
if(i%2 == 0) text.data()[i] = text.data()[i] +20;
}
}
}
Don't bother about macros like Q_OBJECT, qmake takes care of it.
And my errors: lab1.cpp:23: error: expected unqualified-id at end of input (line 23 is the "}" that closes the slot
Any thoughts that what is failing?
Another thing is that I don't think that is correct the way I pass from capitals to normals (text.data()[i] +20) but that is another question that I hope to resolve on my own :p!
Comment