2

I want to add Qdate to my table say QTableview.The problem is if i convert it into string i can add and retrieve the data.But i want to store as date only in my model.

void MainWindow::setUpTabel()
{
   QDateTime myDate;
   myDate.setDate(QDate::currentDate());
   //myModel 
   QStandardItemModel model = new QStandardItemModel(this);
   QStandardItem *item = new QStandardItem;
   item.setData(myDate,Qt::UserRole);
   //Myview is also created and set the model to it
   m_tableView->setModel(model);
 }

The problem is i'm not able to see the date in my table.

Maxim Makhun
  • 2,197
  • 1
  • 22
  • 26
anbu selvan
  • 725
  • 3
  • 13
  • 41

1 Answers1

-1

As the documentation says, you must set the item into the model specifying the row and columng where you are going to set the item.

http://qt-project.org/doc/qt-4.8/qstandarditemmodel.html

Modifying your code:

void MainWindow::setUpTabel()
{
   int row = 0, column = 0; // here you decide where is the item

   QDateTime myDate;
   myDate.setDate(QDate::currentDate());

   QStandardItemModel model = new QStandardItemModel(this);
   QStandardItem *item = new QStandardItem(myDate);

   model.setItem(row, column, item);

   m_tableView->setModel(model);
 }
carlosvin
  • 979
  • 9
  • 22