Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Widget not updating, Signals and Slots
Forum Updated to NodeBB v4.3 + New Features

Widget not updating, Signals and Slots

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 2.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mfessler
    wrote on last edited by
    #1

    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();
    

    }@

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • JKSHJ Offline
        JKSHJ Offline
        JKSH
        Moderators
        wrote on last edited by
        #3

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

        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mfessler
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • JKSHJ Offline
            JKSHJ Offline
            JKSH
            Moderators
            wrote on last edited by
            #5

            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?

            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mfessler
              wrote on last edited by
              #6

              [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
              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                then can you show homeCommand.cpp ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved