Dont see new signal on outside class



  • Hi,
    I reimpement QTextEdit:

    .h
    [code]
    #ifndef MYTEXTEDIT_H
    #define MYTEXTEDIT_H

    #include <QtGui>
    #include <QtCore>

    class MyTextEdit : public QTextEdit
    {
    Q_OBJECT
    public:
    explicit MyTextEdit(QWidget *parent);

    private:
    bool isEdited;

    signals:
    void signalMouseDoubleClickEvent(QMouseEvent *e);

    public slots:

    protected:
    void mouseDoubleClickEvent(QMouseEvent *e);
    };

    #endif // MYTEXTEDIT_H
    [/code]

    .cpp
    [code]
    #include "mytextedit.h"

    MyTextEdit::MyTextEdit(QWidget *parent)
    {
    setParent( parent );
    isEdited = false;

    }

    void MyTextEdit::mouseDoubleClickEvent(QMouseEvent *e)
    {
    QTextEdit::mouseDoubleClickEvent(e);
    if( !anchorAt( e->pos() ).isEmpty() )
    emit signalMouseDoubleClickEvent(e);
    }
    [/code]

    now if i declar new verbal MyTextEdit type then no have signal i dont know why. Is somting like public and prtected signal ???

    main.cpp
    [code]
    MyTextEdit *TextEdit;
    TextEdit = new MyTextEdit(this);

    connect(TextEdit, SIGNAL(),

    [/code]


  • Moderators

    Your post breaks with the interesting part. How do you connect your signal?
    Give the complete statement.
    Do you get an error message?



  • Signals are always protected from a technical point of view (only the class itself and its subclasses can emit them), and always public from a logical point of view (everyone can connect to a signal).

    The code you've posted works correctly. Make sure that you've included the header file mytextedit.h (no forward declaration) and that you've re-run qmake after adding the signal.

    In addition, you are missing a call to the base class constructor.
    @
    MyTextEdit::MyTextEdit(QWidget *parent = 0) : QTextEdit(parent)
    {
    isEdited = false;
    }
    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.