Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. why i am not able to see text data on dynamic label ?
Forum Updated to NodeBB v4.3 + New Features

why i am not able to see text data on dynamic label ?

Scheduled Pinned Locked Moved Solved Mobile and Embedded
6 Posts 4 Posters 490 Views 2 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.
  • Q Offline
    Q Offline
    Qt embedded developer
    wrote on last edited by
    #1

    #include "widget.h"
    #include "ui_widget.h"
    #include <QLabel>
    #include <qdatetime.h>
    #include <qtimer.h>
    #include <qthread.h>
    #define TIMEOUT 300

    Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
    {
    ui->setupUi(this);

    QTimer::singleShot(1000,this, SLOT(shutdownlabel()));
    
    mtime=   QDateTime::currentMSecsSinceEpoch();
    

    }

    Widget::~Widget()
    {
    delete ui;
    }

    void Widget::shutdownlabel()
    {

    qint64 Newtime  = QDateTime::currentMSecsSinceEpoch() - mtime;
    //PRINT_INFO<<"newtime: " << Newtime/1000;
    Timeremain =  TIMEOUT - (Newtime/1000);
    
    QLabel *label = new QLabel(ui->frame_2);
    label->setStyleSheet("border:1px solid black;text-align:cetre;");
    label->setGeometry(50,1,202,20);
    label->setText("first line");
    label->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
    QThread::msleep(200);
    

    }

    JonBJ 1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      What is ui->frame_2?

      You don't call label->show() anywhere, so it probably stays hidden.

      (Z(:^

      1 Reply Last reply
      3
      • Q Qt embedded developer

        #include "widget.h"
        #include "ui_widget.h"
        #include <QLabel>
        #include <qdatetime.h>
        #include <qtimer.h>
        #include <qthread.h>
        #define TIMEOUT 300

        Widget::Widget(QWidget *parent) :
        QWidget(parent),
        ui(new Ui::Widget)
        {
        ui->setupUi(this);

        QTimer::singleShot(1000,this, SLOT(shutdownlabel()));
        
        mtime=   QDateTime::currentMSecsSinceEpoch();
        

        }

        Widget::~Widget()
        {
        delete ui;
        }

        void Widget::shutdownlabel()
        {

        qint64 Newtime  = QDateTime::currentMSecsSinceEpoch() - mtime;
        //PRINT_INFO<<"newtime: " << Newtime/1000;
        Timeremain =  TIMEOUT - (Newtime/1000);
        
        QLabel *label = new QLabel(ui->frame_2);
        label->setStyleSheet("border:1px solid black;text-align:cetre;");
        label->setGeometry(50,1,202,20);
        label->setText("first line");
        label->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
        QThread::msleep(200);
        

        }

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #3

        @Qt-embedded-developer said in why i am not able to see text data on dynamic label ?:

        QThread::msleep(200);

        Additional to @sierdzio , what is this doing here? It's going to cause you problems....

        1 Reply Last reply
        1
        • Q Offline
          Q Offline
          Qt embedded developer
          wrote on last edited by
          #4

          when i wrote below part in constructor it shows label data without label->show()

          why this happen ?

          qint64 Newtime = QDateTime::currentMSecsSinceEpoch() - mtime;
          //PRINT_INFO<<"newtime: " << Newtime/1000;
          Timeremain = TIMEOUT - (Newtime/1000);

          QLabel *label = new QLabel(ui->frame_2);
          label->setStyleSheet("border:1px solid black;text-align:cetre;");
          label->setGeometry(50,1,202,20);
          label->setText("first line");
          label->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
          QThread::msleep(200);

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

            Hi,

            As @sierdzio already wrote, you do not call show on your newly created QLabel.

            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
            • Q Qt embedded developer

              when i wrote below part in constructor it shows label data without label->show()

              why this happen ?

              qint64 Newtime = QDateTime::currentMSecsSinceEpoch() - mtime;
              //PRINT_INFO<<"newtime: " << Newtime/1000;
              Timeremain = TIMEOUT - (Newtime/1000);

              QLabel *label = new QLabel(ui->frame_2);
              label->setStyleSheet("border:1px solid black;text-align:cetre;");
              label->setGeometry(50,1,202,20);
              label->setText("first line");
              label->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
              QThread::msleep(200);

              sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #6

              @Qt-embedded-developer said in why i am not able to see text data on dynamic label ?:

              when i wrote below part in constructor it shows label data without label->show()

              why this happen ?

              Because then your Widget already has this label created when you call Widget->show() elsewhere in your code.

              (Z(:^

              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