Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Unable to Display both time and date together using QLCDnumber
Qt 6.11 is out! See what's new in the release blog

Unable to Display both time and date together using QLCDnumber

Scheduled Pinned Locked Moved Qt Creator and other tools
4 Posts 3 Posters 3.5k 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.
  • R Offline
    R Offline
    rajatgupta431
    wrote on last edited by
    #1

    @#include<lcdtd.h>
    #include<QtGui>

    lcdtd::lcdtd(QLCDNumber *parent):QLCDNumber(parent)
    {
    setWindowTitle("Time And Date");
    QTimer *timer = new QTimer(this);
    connect(timer,SIGNAL(timeout()),this,SLOT(showDate()));
    QTimer *timex = new QTimer(this);
    connect(timex,SIGNAL(timeout()),this,SLOT(showTime()));
    timex->start(1000);

    resize(200,200);
    setDigitCount(10);
    

    }

    void lcdtd::showDate()
    {
    QDate date = QDate::currentDate();

    QString tex= date.toString("dd.MM.yyyy");
    this->display(tex);
    

    }
    void lcdtd::showTime()
    {
    QTime time = QTime::currentTime();

    QString text= time.toString("hh:mm:ss ap");
    this->display(text);
    

    }
    @

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Code_ReaQtor
      wrote on last edited by
      #2

      bq. this->display(tex);

      I guess "display()" overrides the previous input in the QLCDNumber and what will be shown will be the last one. Why not use QDateTime, instead of separate QDate and QTime?

      Please visit my open-source projects at https://github.com/Code-ReaQtor.

      1 Reply Last reply
      0
      • R Offline
        R Offline
        rajatgupta431
        wrote on last edited by
        #3

        Your solution is very right. But is there any way to use both QDate and QTime and display both of them in a same window??

        1 Reply Last reply
        0
        • K Offline
          K Offline
          koahnig
          wrote on last edited by
          #4

          [quote author="rajatgupta431" date="1359198118"]@#include<lcdtd.h>
          #include<QtGui>

          lcdtd::lcdtd(QLCDNumber *parent):QLCDNumber(parent)
          {
          setWindowTitle("Time And Date");
          // QTimer *timer = new QTimer(this);
          // connect(timer,SIGNAL(timeout()),this,SLOT(showDate()));
          QTimer *timex = new QTimer(this);
          connect(timex,SIGNAL(timeout()),this,SLOT(showTime()));
          timex->start(1000);

          resize(200,200);
          setDigitCount(10);
          

          }

          void lcdtd::showTime()
          {
          QDate date = QDate::currentDate();

          QString tex= date.toString("dd.MM.yyyy");
          QTime time = QTime::currentTime();
          
          QString text= tex + " " + time.toString("hh:mm:ss ap");
          this->display(text);
          

          }
          @[/quote]
          something crude and very simple would be this above.

          More sophisticated when you are holding somewhere the converted date and reuse.

          Also you can use "QDateTime":http://qt-project.org/doc/qt-5.0/qtcore/qdatetime.html#currentDateTime there is also "toString":http://qt-project.org/doc/qt-5.0/qtcore/qdatetime.html#toString available

          Vote the answer(s) that helped you to solve your issue(s)

          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