Page 2 of 2 FirstFirst 12
Results 21 to 27 of 27

Thread: display time as as string ?

  1. #21
    Join Date
    Jan 2009
    Location
    The Netherlands and Spain
    Posts
    150
    Thanks
    6
    Thanked 18 Times in 18 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: display time as as string ?

    We need to see more of your code.

  2. #22
    Join Date
    Jan 2010
    Posts
    63
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: display time as as string ?

    That is not what I want. I did pass the QTime and got that too.
    I want the default time to change to what the user types in the TimeEdit field.
    For instance, if he changes it to 1:30 pm when he clicks "accept" then the a message box pops up and shows " 1:30 pm"
    Is this possible ?

  3. #23
    Join Date
    Jan 2010
    Posts
    63
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: display time as as string ?

    Here calandertime.cpp

    Qt Code:
    1. #include "calendartime.h"
    2. #include<QtGui>
    3. #include<Qtime>
    4. #include<QMessageBox>
    5. #include<QString>
    6.  
    7.  
    8. calendartime::calendartime(QWidget *parent) :
    9. QDialog(parent)
    10.  
    11. {
    12.  
    13. setupUi(this);
    14.  
    15. this->resize(355, 180);
    16. secondaryGroupBox->hide();
    17. connect(moreButton, SIGNAL(clicked(bool)),this , SLOT(display_time(bool)));
    18. connect(acceptButton, SIGNAL(clicked(bool)),this , SLOT(display_message()));
    19.  
    20. }
    21.  
    22. calendartime::~calendartime()
    23. {
    24. delete this;
    25. }
    26.  
    27.  
    28. void calendartime::display_time(bool)
    29. {
    30.  
    31. this->resize(355,273);
    32. secondaryGroupBox->show();
    33.  
    34.  
    35. }
    36.  
    37. void calendartime:: display_message()
    38. {
    39. QMessageBox msgbox;
    40. QTimeEdit timeEdit;
    41. QString timeInString = timeEdit.toString("h:m:s ap");
    42. msgbox.setText(timeInString);
    43. msgbox.exec();
    44. }
    To copy to clipboard, switch view to plain text mode 

    CALENDERTIME.H
    Qt Code:
    1. #ifndef CALENDARTIME_H
    2. #define CALENDARTIME_H
    3.  
    4. #include <QtGui>
    5. #include "ui_calendartime.h"
    6.  
    7.  
    8. class calendartime: public QDialog, public Ui::calendartime
    9. {
    10. Q_OBJECT
    11. public:
    12. calendartime(QWidget *parent = 0);
    13. ~calendartime();
    14.  
    15. public slots:
    16. void display_time(bool);
    17. void display_message();
    18. };
    19.  
    20. #endif // CALENDARTIME_H
    To copy to clipboard, switch view to plain text mode 

  4. #24
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: display time as as string ?

    Yes, it's possible, but you are creating a QTimeEdit object in your display_message method, and so the time there will always be 12:00 and not be editable. You need to use the object in the ui namespace.

  5. #25
    Join Date
    Jan 2010
    Posts
    63
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: display time as as string ?

    I tried that too.
    Anyways here is that code:
    Qt Code:
    1. /********************************************************************************
    2. ** Form generated from reading UI file 'calendartime.ui'
    3. **
    4. ** Created: Fri Jan 29 08:16:46 2010
    5. ** by: Qt User Interface Compiler version 4.6.0
    6. **
    7. ** WARNING! All changes made in this file will be lost when recompiling UI file!
    8. ********************************************************************************/
    9.  
    10. #ifndef UI_CALENDARTIME_H
    11. #define UI_CALENDARTIME_H
    12.  
    13. #include <QtCore/QVariant>
    14. #include <QtGui/QAction>
    15. #include <QtGui/QApplication>
    16. #include <QtGui/QButtonGroup>
    17. #include <QtGui/QCalendarWidget>
    18. #include <QtGui/QDialog>
    19. #include <QtGui/QGroupBox>
    20. #include <QtGui/QHeaderView>
    21. #include <QtGui/QPushButton>
    22. #include <QtGui/QTimeEdit>
    23.  
    24. QT_BEGIN_NAMESPACE
    25.  
    26. class Ui_calendartime
    27. {
    28. public:
    29. QGroupBox *secondaryGroupBox;
    30. QTimeEdit *timeEdit;
    31. QPushButton *acceptButton;
    32. QPushButton *moreButton;
    33. QPushButton *cancelButton;
    34. QGroupBox *groupBox;
    35. QCalendarWidget *calendarWidget;
    36.  
    37. void setupUi(QDialog *calendartime)
    38. {
    39. if (calendartime->objectName().isEmpty())
    40. calendartime->setObjectName(QString::fromUtf8("calendartime"));
    41. calendartime->resize(355, 273);
    42. calendartime->setMaximumSize(QSize(368, 273));
    43. secondaryGroupBox = new QGroupBox(calendartime);
    44. secondaryGroupBox->setObjectName(QString::fromUtf8("secondaryGroupBox"));
    45. secondaryGroupBox->setGeometry(QRect(20, 180, 211, 80));
    46. secondaryGroupBox->setFocusPolicy(Qt::StrongFocus);
    47. timeEdit = new QTimeEdit(secondaryGroupBox);
    48. timeEdit->setObjectName(QString::fromUtf8("timeEdit"));
    49. timeEdit->setGeometry(QRect(10, 20, 118, 22));
    50. timeEdit->text();
    51. acceptButton = new QPushButton(secondaryGroupBox);
    52. acceptButton->setObjectName(QString::fromUtf8("acceptButton"));
    53. acceptButton->setGeometry(QRect(130, 20, 75, 23));
    54. moreButton = new QPushButton(calendartime);
    55. moreButton->setObjectName(QString::fromUtf8("moreButton"));
    56. moreButton->setGeometry(QRect(270, 10, 75, 23));
    57. cancelButton = new QPushButton(calendartime);
    58. cancelButton->setObjectName(QString::fromUtf8("cancelButton"));
    59. cancelButton->setGeometry(QRect(270, 50, 75, 23));
    60. groupBox = new QGroupBox(calendartime);
    61. groupBox->setObjectName(QString::fromUtf8("groupBox"));
    62. groupBox->setGeometry(QRect(10, 10, 241, 151));
    63. calendarWidget = new QCalendarWidget(groupBox);
    64. calendarWidget->setObjectName(QString::fromUtf8("calendarWidget"));
    65. calendarWidget->setGeometry(QRect(10, 20, 221, 121));
    66.  
    67. retranslateUi(calendartime);
    68. QObject::connect(cancelButton, SIGNAL(clicked(bool)), calendartime, SLOT(close()));
    69. QObject::connect(cancelButton, SIGNAL(toggled(bool)), secondaryGroupBox, SLOT(setVisible(bool)));
    70. QObject::connect(acceptButton, SIGNAL(clicked(bool)), timeEdit, SLOT(selectAll()));
    71. QObject::connect(acceptButton, SIGNAL(clicked(bool)), calendartime, SLOT(accept()));
    72.  
    73. QMetaObject::connectSlotsByName(calendartime);
    74. } // setupUi
    75.  
    76. void retranslateUi(QDialog *calendartime)
    77. {
    78. calendartime->setWindowTitle(QApplication::translate("calendartime", "calendartime", 0, QApplication::UnicodeUTF8));
    79. secondaryGroupBox->setTitle(QApplication::translate("calendartime", "Time Edit", 0, QApplication::UnicodeUTF8));
    80. acceptButton->setText(QApplication::translate("calendartime", "Accept", 0, QApplication::UnicodeUTF8));
    81. moreButton->setText(QApplication::translate("calendartime", "More", 0, QApplication::UnicodeUTF8));
    82. cancelButton->setText(QApplication::translate("calendartime", "Quit", 0, QApplication::UnicodeUTF8));
    83. groupBox->setTitle(QApplication::translate("calendartime", "Calendar Box", 0, QApplication::UnicodeUTF8));
    84. } // retranslateUi
    85.  
    86. };
    87.  
    88. namespace Ui {
    89. class calendartime: public Ui_calendartime {};
    90. } // namespace Ui
    91.  
    92. QT_END_NAMESPACE
    93.  
    94. #endif // UI_CALENDARTIME_H
    To copy to clipboard, switch view to plain text mode 

    Here is the modified display_message method:
    Qt Code:
    1. void calendartime:: display_message()
    2. {
    3. QMessageBox msgbox;
    4. QTimeEdit timeEdit;
    5.  
    6. QString timeInString = timeEdit.time().toString("h:m:s ap");
    7. msgbox.setText(timeEdit.text());
    8. msgbox.exec();
    9. }
    To copy to clipboard, switch view to plain text mode 

    it stil displays the default time. arrgh
    Last edited by Petr_Kropotkin; 29th January 2010 at 13:26.

  6. #26
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: display time as as string ?

    Quote Originally Posted by Petr_Kropotkin View Post
    Here is the modified display_message method:
    Qt Code:
    1. void calendartime:: display_message()
    2. {
    3. QMessageBox msgbox;
    4. QTimeEdit timeEdit;
    5.  
    6. QString timeInString = timeEdit.time().toString("h:m:s ap");
    7. msgbox.setText(timeEdit.text());
    8. msgbox.exec();
    9. }
    To copy to clipboard, switch view to plain text mode 

    it stil displays the default time. arrgh
    But You have again and again local variable timeEdit. In class Ui_calendartime You have public variable timeEdit and this is what You want. Yours display_message method must look like this :
    Qt Code:
    1. void calendartime:: display_message()
    2. {
    3. QMessageBox msgbox;
    4.  
    5. QString timeInString = timeEdit->time().toString("h:m:s ap");
    6. msgbox.setText(timeEdit.text());
    7. msgbox.exec();
    8. }
    To copy to clipboard, switch view to plain text mode 

    Sorry for my comment but they are bases of C++ (range of variables).

  7. #27
    Join Date
    Jan 2010
    Posts
    63
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: display time as as string ?

    That works !
    Thanks
    Last edited by Petr_Kropotkin; 29th January 2010 at 16:19.

Similar Threads

  1. real time data display
    By hammer256 in forum Qt Programming
    Replies: 13
    Last Post: 25th March 2013, 16:47
  2. How to display individual character of a string?
    By cooper in forum Qt Programming
    Replies: 2
    Last Post: 15th July 2009, 05:19
  3. Display a QWidget on two X-Server at the same time
    By tarod in forum Qt Programming
    Replies: 0
    Last Post: 1st July 2008, 12:55
  4. QTableView does not display time string correctly
    By ad5xj in forum Qt Programming
    Replies: 1
    Last Post: 5th August 2007, 20:35
  5. Display the camera frame in real time
    By alex_lue in forum Qt Programming
    Replies: 8
    Last Post: 27th July 2007, 10:31

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.