Widget not updating, Signals and Slots



  • I have two widgets that are each in there own class. I want to send a string from one widget to the other. I am using signals and slots to do this. However, the widget does not update. I know the signals and slots are working as intended because I have a qDebug() line that prints out everytime the slot the called. Is there something in Qt that can block a widget from updating??? This makes no sense to me.

    @
    messagelogcommand.h:
    class MessageLogCommand : public QWidget
    {
    Q_OBJECT

    public:
    explicit MessageLogCommand(QWidget *parent = 0);

       QPlainTextEdit *messageLog;
    

    public Q_SLOTS:
    void updateWidgets(const QString &text)
    {
    messageLog->appendPlainText(text);
    }

    homeCommand.h:
    class homeCommand : public QWidget
    {
    Q_OBJECT

    public:
    explicit homeCommand(QWidget *parent = 0);
    Q_SIGNALS:
    void textChanged(const QString &text);

    homeCommand.cpp
    Q_EMIT textChanged("OMG");

    main.cpp
    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    MainWindow w;

    w.show();
    
    MessageLogCommand s;
    homeCommand m;
    QObject::connect(&m, SIGNAL(textChanged(QString)), &s, SLOT(updateWidgets(QString)));
    
    return a.exec();
    

    }@


  • Lifetime Qt Champion

    Hi,

    Without any code it will be difficult to help you. Can you share at least the slot implementation ?


  • Moderators

    You'll need to show us how you try to update the widget.



  • I edited my original post with some bare minimum code. Let me know if this isn't enough/what else you need to see


  • Moderators

    Thanks for the minimal code; that does make your issue easier to understand. One more request: Please add '@' before and after your code to format it for readability. :)

    Some questions:

    Did you make the connection before emitting your signal?

    Did you put qDebug() inside updateWidgets()? What does it show?

    Did you instantiate messageLog before emitting your signal?

    Is your QPlainTextEdit visible?

    Do you see any error/warning messages when running your app?



  • [quote author="JKSH" date="1390578493"]Thanks for the minimal code; that does make your issue easier to understand. One more request: Please add '@' before and after your code to format it for readability. :)

    Some questions:

    Did you make the connection before emitting your signal?

    Did you put qDebug() inside updateWidgets()? What does it show?

    Did you instantiate messageLog before emitting your signal?

    Is your QPlainTextEdit visible?

    Do you see any error/warning messages when running your app?[/quote]

    1. Yes, I also emit the signal every second indefinitely
    2. Yes, and yes it does show
    3. Yes
    4. Yes, it is visible, if I update the widget from the slot that is triggered once a second from that class the widget updates
    5. No, no errors or warnings

  • Lifetime Qt Champion

    then can you show homeCommand.cpp ?


Log in to reply
 

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