Subclassed QPlainTextEdit, how can call in other class?



  • This is my main that creates the RepairDevices window:

    #include "repairdevices.h"
    #include <QtWidgets>
    
    
    
    int main(int argc, char * argv[])
    {
        Q_INIT_RESOURCE(books);
    
        QApplication app(argc, argv);    
    
        RepairDevices win;
        win.show();
    
        return app.exec();
    }
    

    RepairDevices.cpp has slot setDirty:

    public slots:    
        void setDirty(QString text);
    

    I have subclassed QPlainTextEdit, to a class named 'notifierText'.
    I have promoted a QPlainTextEdit, named sn_txt, to this class.
    The sn_txt is in my form, created with Qt Designer.

    This is my class' source:

    notifierText::notifierText(QWidget *parent) : QPlainTextEdit(parent)
    {
        QString thistext = this->toPlainText();
        connect( this, SIGNAL(textChanged(QString)), parent, SLOT(setDirty(thistext)) );    
    }
    

    Obviously, the 'parent, SLOT(...' is wrong.
    Ho can I call the setDirty function in RepairDevices.cpp?



  • It's RepairDevices that has to connect to notifierText not the other way around



  • I did it like this in RepairDevices constructor:
    connect(ui.sn_txt,SIGNAL(textChanged(QString)),this,SLOT(setDirty(QString)));

    But I get a warning:
    QObject::connect: No such signal QPlainTextEdit::textChanged(QString)

    And it's not working.
    What am I doing wrong?


  • Qt Champions 2016

    @Panoss
    Hi
    Does notifierText have a Q_OBJECT macro ?



  • Hi mrjj.
    I demoted it to QPlainTextEdit, I don't use the notifierText class.


  • Qt Champions 2016

    @Panoss
    Hi :)
    ok so sn_txt is now a 100% normal QPlainTextEdit and not your class?
    Did you clean, rebuild all after changing back?



  • Yes it 's a pure QPlainTextEdit .
    I cleaned and rebuild but the same happens.


  • Qt Champions 2016

    @Panoss
    show the new current code then.
    It normally just works.



  • This is the connection in RepairDevices' constructor:

    connect(ui.sn_txt,SIGNAL(textChanged(QString)),this,SLOT(setDirty(QString)));
    

    This is the declaration of the function:

    public slots:
        void setDirty(QString txt);
    

    This is the function:

     void RepairDevices::setDirty(QString txt)
     {
         qDebug() << "text=" << txt;   
     }
    


  • When I change to textChanged(), it works.
    But I don't have the text of the sn_txt.

    And I see here: void QPlainTextEdit::textChanged()


  • Qt Champions 2016

    @Panoss said in Subclassed QPlainTextEdit, how can call in other class?:

    textChanged

    i dont think it has version where it emits the whole text. lineEdit has.

    so you must use QPlainTextEdit::textChanged() and

    void RepairDevices::setDirty()
    {
    qDebug() << "text=" << ui->plaintext->toPlainText();
    }



  • The reason I subclassed it, was because I wanted the class to connect to RepairDevices 's slot.
    (that is, the code: connect blah blah to be in the class)
    This is not possible, so it's canceled.
    Thank you for your help.


  • Qt Champions 2016

    @Panoss

    Well the normal signal does not have QString but in a subclass
    you could easy make a new signal that would have and
    then emit it in the subclass and it would be as you wanted.


Log in to reply
 

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