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. 'messageLabel' was not declared in this scope
Forum Updated to NodeBB v4.3 + New Features

'messageLabel' was not declared in this scope

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 2 Posters 3.7k 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.
  • W Offline
    W Offline
    WhatIf
    wrote on last edited by WhatIf
    #1

    I'm trying to display a success/failure message on QDialog label for 5 secs and the QDialog should close automatically. What I'm having difficulty with is updating the text of the label. Here is the code:

    void Camera::displayAttemptedSaveResult(QString msg)
    {
        AttemptedSaveResultDisplay saveResult;
        saveResult.setModal(true);
        saveResult.setWindowFlags(Qt::CustomizeWindowHint); 
        saveResult.setWindowFlags(Qt::FramelessWindowHint); 
        messageLabel->setText(msg);
        saveResult.exec();
        QTimer::singleShot(5000,&saveResult, SLOT(close()));
    }
    

    messageLabel->setText(msg); produces an error "'messageLabel' was not declared in this scope"

    How can I modify the QDialog label text?

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

      Hi,

      is messageLabel a widget from AttemptedSaveResultDisplay ?

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

      W 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        is messageLabel a widget from AttemptedSaveResultDisplay ?

        W Offline
        W Offline
        WhatIf
        wrote on last edited by
        #3

        @SGaist

        The QDialog and messageLabel were created using Qt Designer and I can't use ui->messageLabel->setText(msg); because AttemptedSaveResultDisplay is a static function? How can I get around this problem?

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

          AttemptedSaveResultDisplay is not a static function but a class. The cleanest way to do that is to add a setter to AttemptedSaveResultDisplay (e.g. setMessage) that will call ui->messageLabel->setText(msg);

          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
          • W Offline
            W Offline
            WhatIf
            wrote on last edited by
            #5

            I'm considering a different solution to my problem but it seems that there is another problem with the code. I intended for the QDialog to pop up for 5 seconds, then closes but this line

            QTimer::singleShot(5000,&saveResult, SLOT(close()));
            

            doesn't seem to get the QDialog to close after 5 seconds. What am I doing wrong?

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

              That's normal, you call it after saveResult.exec(); which is a blocking call.

              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
              • W Offline
                W Offline
                WhatIf
                wrote on last edited by WhatIf
                #7

                Thank you very much.....didn't pay attention to exec() :)

                I have 3 last questions about the code, hopefully!

                void Camera::displayAttemptedSaveResult(QString msg)
                {
                    AttemptedSaveResultDisplay saveResult;
                    saveResult.setModal(true);
                    saveResult.setWindowFlags(Qt::CustomizeWindowHint); 
                    saveResult.setWindowFlags(Qt::FramelessWindowHint); 
                
                    QLabel *message = new QLabel(&saveResult);
                    message->setStyleSheet("QLabel { font-size:16pt; color:#FF1900;}");
                    QHBoxLayout *layout = new QHBoxLayout();
                    message->setText(msg);
                    message->setAlignment(Qt::AlignHCenter);
                    message->setFixedWidth(300);
                    layout->addWidget(message);
                    saveResult.setLayout(layout);
                
                    QTimer::singleShot(5000,&saveResult, SLOT(close()));
                    saveResult.exec();
                }
                
                1. I come from java background were object collection is done automatically. Is
                QLabel *message = new QLabel(&saveResult);
                

                the correct way to create the QLabel so it won't cause memory leaks?

                1. Is there a better way than
                message->setFixedWidth(300);
                

                to make sure all text is displayed automatically whether long or short string is used? If I comment it out, a small part of the text is displayed.

                1. The text is displayed in the top right of the dialog even though I intended for it to display centered vertically and horizontally,
                 message->setAlignment(Qt::AlignHCenter);
                

                What am I missing?

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8
                  1. Since you put message in a layout that you set on saveResult, then there no need to pass the parent when constructing message.

                  Doesn't AttemptedSaveResultDisplay already have a layout ?

                  1. message should resize itself to match the size of the text.

                  2. The text might be centered in the label but the label could be at the wrong position.

                  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