How to dispaly date in format dd/mm/yyyy using QSqlTableModel
Hi,
How to dispaly date in format dd/mm/yyyy using QSqlTableModel
and through QtableView.
By default it displays date in yyyy-mm-dd format.
Re: How to dispaly date in format dd/mm/yyyy using QSqlTableModel
QWidget has a property called locale since Qt 4.3. This is used to localize dates and times in items views. In earlier versions, you can do it the way our wiki describes: Localizing dates and times in item views.
Re: How to dispaly date in format dd/mm/yyyy using QSqlTableModel
Hi,
thanks for your help.
Please tell me how to use
"Qt::EditRole" with the model.
I have stored the date in mysql database.
And while displaying it in the view it
need to be in rhe format dd/mm/yyyy.
please help me.
Re: How to dispaly date in format dd/mm/yyyy using QSqlTableModel
Which version of Qt are you using?
Re: How to dispaly date in format dd/mm/yyyy using QSqlTableModel
Re: How to dispaly date in format dd/mm/yyyy using QSqlTableModel
Quote:
Originally Posted by
bala
I am using Qt 4.2.3.
Alright, so you might want to try the approach shown in our wiki. Start with subclassing QSqlTableModel and reimplementing data(). First, you'll get the actual value from base class. Then, you do some adjustments when appropriate, when certain conditions are met:
Code:
QVariant MySqlTableModel
::data(const QModelIndex
& index,
int role
) const {
if (!index.isValid())
// get the actual value from base class
// do adjustments if necessary
if (role == Qt::DisplayRole && index.column() == theColumnWhichContainsDates)
{
QDate date
= value.
toDate();
value = date.toString("dd/MM/yyyy");
}
return value;
}
Re: How to dispaly date in format dd/mm/yyyy using QSqlTableModel
Hi,
I have implemented the code.
It was compiling fine but while
running it shows segmentation fault.
Re: How to dispaly date in format dd/mm/yyyy using QSqlTableModel
Compile the app in debug mode ("qmake -config debug"), run it via debugger ("gdb ./app"), make it crash, and paste backtrace ("bt") here.