Set specific date in DateEdit
Hi I have this problem:
I have a mysql table and in one field I have a date, I want put this date in a DateEdit.
I make this code:
dataricovero is a string like this: "2012-01-17"
Code:
QDate date
= QDate::fromString(dataricovero,
"yyyy-MM-dd");
ui->dateEditDataricovero->setDate(date);
but dont work.
If I do
Code:
ui->dateEditDataricovero->setDate(date);
All work fine but I dont want set the current time but the time read in sql query.
Please help me!
Thank you
P.S. Sorry for my english ;(
Re: Set specific date in DateEdit
What about it does not work? This:
Code:
#include <QtGui>
#include <QDebug>
int main(int argc, char *argv[])
{
QString dataricovero
("2012-01-17");
QDate date
= QDate::fromString(dataricovero,
"yyyy-MM-dd");
// OR QDate date= QDate::fromString(dataricovero,Qt::ISODate);
qDebug() << date;
e.setDate(date);
e.show();
return app.exec();
}
outputs 'QDate("Tue Jan 17 2012")' (English locale obviously) and the date edit contains that date.
What is the data type of the Mysql column this value is coming from?
Are you sure that dataricovero is a string in the format you think?
Re: Set specific date in DateEdit
Thank you for reply.
Now it works, the error was in the string, it was (2012-01-17 ) with the final space!
I remove the space and it now work! Thank you.
I have another problem:
I want generate one or more QLabel runtime and put it in a container with scrollbar.
What container I must use?
And how I can add the QLabel to the container?
I make this:
Code:
layout.addWidget(&labelAtt);
ui->tabCartella->widget(6)->setLayout(&layout);
labelAtt.show();
But the label is not show and the QVBoxLayout dont have a scrollbar!
Thank you again for the answer!
Re: Set specific date in DateEdit
You are creating the QVBoxLayout and, I guess, the QLabel on the stack. At the end of that scope these objects will be destroyed, which will remove them form the UI.
Allocate them on the heap with operator new.
Re: Set specific date in DateEdit
I dont have undestrand,
can you explain me with some example?
Sorry but I'm a new in the world of Qt!
Thank you!
Re: Set specific date in DateEdit
Create a widget with a layout to which you'll be adding new lables then stick that widget into scroll area.
Something like this:
Code:
MainWindow::MainWindow()
{
container->setLayout( lay );
sa->setWidget( container );
this->setCentralWidget( sa );
lay
->addWidget
( new QLabel( "new label" );
}
Now when you add too many labels to fit on the screen scroll area will show scroll bars to navigate through widgets content.
Edit:
Forgot to mention that you have to set
Code:
sa->setWidgetResizable( true );
otherwise scroll area will not resize container widget as more contents is added.
Re: Set specific date in DateEdit
Hi tnak you so much for your help.
I try the code and it works, but what I want to do is add a scrollarea and put into labels in a QTAbWidget.
In the mainWindow I have a QTabWidget with the name tabCartella whit 6 tab, I want put a scroll area and labels into the widget 6 (the last).
I try with this:
Code:
QWidget* container
= ui
->tabCartella
->widget
(6);
container->setLayout( lay );
sa->setWidget(container);
sa->setWidgetResizable( true );
ui->tabCartella->setCurrentWidget(container);
lay
->addWidget
( new QLabel( "new label" ));
But when I run this code the last tab (tho one where I wans put labels) disappear!
Please help me
Thank you so much for your Help.