PDA

View Full Version : How to default Date-Edit Widget to system date



JohnToddSr
17th January 2007, 15:54
:D I have just discovered Qt!. I have been looking at all of its wonderful features. In designing my first program using Designer I selected the Date-Edit Widget but can find no way to set its default value to the current system date. Do I have to do this programatically? Same question for Time-Edit Widget.

jpn
17th January 2007, 16:40
:D I have just discovered Qt!. I have been looking at all of its wonderful features.
First of all, congratulations for such a great pick! ;)



In designing my first program using Designer I selected the Date-Edit Widget but can find no way to set its default value to the current system date. Do I have to do this programatically? Same question for Time-Edit Widget.
Yes, you have to do it programmatically:

dateEdit->setCurrentDate(QDate::currentDate());

JohnToddSr
17th January 2007, 18:31
Thanks, for the input but...Ok, I guess I'm a little slow on getting this.

Here's my code:


MainWindow::MainWindow( QWidget* parent ) : QMainWindow( parent )
{
setupUi( this );
frame_Top->hide();
tabWidget->hide();
dateEdit_tabDetail->setCurrentDate(QDate::currentDate());
}

Within Designer I have named my QObject objectName: dateEdit_tabDetail.
So in my instance I would assume the following applies:
Your example:

dateEdit->setCurrentDate(QDate::currentDate());

becomes


dateEdit_tabDetail->setCurrentDate(QDate::currentDate());

Obviously that is not all there is to it.
I get the following error:

MainWindow.cpp:27:
error: 'class QDateEdit' has no member named 'setCurrentDate'

What am I missing? (besides a brain)

jpn
17th January 2007, 18:39
I get the following error:

MainWindow.cpp:27:
error: 'class QDateEdit' has no member named 'setCurrentDate'

What am I missing?
Sorry. Obviously it's "setDate()", not "setCurrentDate()". See QDateTimeEdit::setDate() for details (QDateEdit inherits QDateTimeEdit).


dateEdit_tabDetail->setDate(QDate::currentDate());

JohnToddSr
17th January 2007, 19:18
Thanks, lots!!! Works as advertised!