Problems about Qt signals and compilation errors

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jekzer
    New Member
    • Sep 2008
    • 2

    Problems about Qt signals and compilation errors

    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!
  • newb16
    Contributor
    • Jul 2008
    • 687

    #2
    Originally posted by Jekzer
    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!
    Last time I used it, qt was moc-ing only .h files , but not .cpp - did it change now? If not, move declaration to .h and definition to .cpp. And, not qt-specifical, if you declared text argument as "const Qstring&", why do you change text.data in function? Pass it by value, textMM(QString text) and then modify.

    Comment

    Working...