QDateTime not accepted by QTableView












2















I am designing a major user interface with several fields and functions.
However in order to shrink the problem I created a small application with 4 columns: name, image, dataDatabase, dateTime.



I have a MainWindow with a QTableView, as soon as I right click inside the QTableView an AddItemDialog opens up with:




  1. nameLineEdit

  2. ImLineEdit

  3. imageLineEdit

  4. dateTimeEdit


The issue that I have is that I can't find a way to accept the 4) dateTimeEdit through the AddItemDialog.



I didn't "go to slot" of the dateTimeEdit as I didn't think that I had to.
I think that I am not doing the proper conversion for the date and time but please advise on what the issue might be.



I am including the most important parts of the application below with the related description of the procedure I followed:



I created an Item with the fields item.h:



class Item
{
public:
Item(const double dateTime,
const QString &name = "", const QString &image = "",
const QByteArray &imagesData = QByteArray());
QString name() const { return mName; }
QString image() const { return mImage; }
QByteArray imagesData() const { return mImagesData; }
double dateTime() const { return mDateTime; }
private:
QString mName;
QString mImage;
QByteArray mImagesData;
double mDateTime;
};


and its related item.cpp



Item::Item(const double dateTime,
const QString &name, const QString &image,
const QByteArray &imagesData)
{
mName = name;
mImage = image;
mImagesData = imagesData;
mDateTime = dateTime;
}


I created a database.h table that will contain the parameters as follows:



class dataBase : public QObject
{
Q_OBJECT
public:
explicit dataBase(QObject *parent = nullptr);
bool inizializationDataBase(const QString &nameDataBase);
bool configureDataBase();
QString getError() const { return mError; }
bool addItem(const Item &item);
private:
QSqlDatabase mDatabase;
QString mError;
};


And its related database.cpp file - I am only including the most important piece of the code for this file:



#define CREATE_TABLE 
" CREATE TABLE IF NOT EXISTS Fish_Table"
" (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL"
", name TEXT NOT NULL"
", image TEXT NOT NULL"
", dataDataBase BLOB NOT NULL"
", dateTime DOUBLE NOT NULL)"

dataBase::dataBase(QObject *parent)
: QObject(parent)
{
}

bool dataBase::inizializationDataBase(const QString &nameDataBase) {
// code
}

bool dataBase::addItem(const Item &item) {
QSqlQuery q;
q.prepare("INSERT INTO Fish_Table (name, image, dataDatabase, dateTime) VALUES (?,?,?,?)");
q.addBindValue(item.name());
q.addBindValue(item.image());
q.addBindValue(item.imagesData());
q.addBindValue(item.dateTime());
bool ok = q.exec();
if (!ok) {
mError = q.lastError().text();
}
return ok;
}


and finally the AddItemDialog.h and AddItemDialog.cpp that contains the fields I am trying to pass to the QTableView of the MainWindow.



AddItemDialog.h



namespace Ui
{
class AddItemDialog;
}

class AddItemDialog : public QDialog
{
Q_OBJECT
public:
explicit AddItemDialog(QWidget *parent = nullptr);
~AddItemDialog();
Item item() const { return mItem; }
private slots:
void on_toolButton_clicked();
void on_buttonBox_accepted();
void on_buttonBox_rejected();
private:
Ui::AddItemDialog *ui;
Item mItem;
};


AddItemDialog.cpp



AddItemDialog::AddItemDialog(QWidget *parent)
: QDialog(parent)
, ui(new Ui::AddItemDialog)
{
ui->setupUi(this);
auto fileSystemModel = new QFileSystemModel(this);
fileSystemModel->setRootPath(QDir::rootPath());
ui->imageLineEdit->setCompleter(new QCompleter(fileSystemModel,this));
QDateTime dateTime;
dateTime.setDate(QDate::currentDate());
}

AddItemDialog::~AddItemDialog()
{
delete ui;
}

void AddItemDialog::on_toolButton_clicked()
{
auto nameDataBase = QFileDialog::getOpenFileName(this, "Open Images", QDir::rootPath(),
"Images (*.png *.jpg *jpeg *.tif *.tiff);;Any type (*.*)");
ui->imageLineEdit->setText(nameDataBase);
}

void AddItemDialog::on_buttonBox_accepted()
{
QFile dataBase(ui->imageLineEdit->text());
if (!dataBase.open(QIODevice::ReadOnly)) {
QMessageBox::critical(this, "Error", dataBase.errorString());
return;
}
mItem = Item(ui->nameLineEdit->text(),
ui->ImLineEdit->text(),dataBase.readAll());
dataBase.close();
accept();
}


So to recap:




  1. I am not sure I provided the right format to the QDateTime conversion on the Item.h / Item.cpp and database.h / database.cpp


  2. I am not sure how to pass the QDateTime from the AddItemDialog.cpp to the MainWindow



Additionally on the AddItemDialog.cpp I am having the following error right on the beginning:
Constructor for AddItemDialog must explicitly initialize the member mItem which does not have a default constructor



Thanks for providing information on this issue that I have been having for a couple of days.










share|improve this question

























  • What database are you using?

    – eyllanesc
    Nov 25 '18 at 19:56











  • hi eyllanesc, I am using QSQLITE

    – Emanuele
    Nov 25 '18 at 20:13











  • you could share your .ui or better your project through github

    – eyllanesc
    Nov 25 '18 at 20:16











  • is it ok if I pass you my Bitbucket?

    – Emanuele
    Nov 25 '18 at 20:20











  • pass me the link of your project

    – eyllanesc
    Nov 25 '18 at 20:26
















2















I am designing a major user interface with several fields and functions.
However in order to shrink the problem I created a small application with 4 columns: name, image, dataDatabase, dateTime.



I have a MainWindow with a QTableView, as soon as I right click inside the QTableView an AddItemDialog opens up with:




  1. nameLineEdit

  2. ImLineEdit

  3. imageLineEdit

  4. dateTimeEdit


The issue that I have is that I can't find a way to accept the 4) dateTimeEdit through the AddItemDialog.



I didn't "go to slot" of the dateTimeEdit as I didn't think that I had to.
I think that I am not doing the proper conversion for the date and time but please advise on what the issue might be.



I am including the most important parts of the application below with the related description of the procedure I followed:



I created an Item with the fields item.h:



class Item
{
public:
Item(const double dateTime,
const QString &name = "", const QString &image = "",
const QByteArray &imagesData = QByteArray());
QString name() const { return mName; }
QString image() const { return mImage; }
QByteArray imagesData() const { return mImagesData; }
double dateTime() const { return mDateTime; }
private:
QString mName;
QString mImage;
QByteArray mImagesData;
double mDateTime;
};


and its related item.cpp



Item::Item(const double dateTime,
const QString &name, const QString &image,
const QByteArray &imagesData)
{
mName = name;
mImage = image;
mImagesData = imagesData;
mDateTime = dateTime;
}


I created a database.h table that will contain the parameters as follows:



class dataBase : public QObject
{
Q_OBJECT
public:
explicit dataBase(QObject *parent = nullptr);
bool inizializationDataBase(const QString &nameDataBase);
bool configureDataBase();
QString getError() const { return mError; }
bool addItem(const Item &item);
private:
QSqlDatabase mDatabase;
QString mError;
};


And its related database.cpp file - I am only including the most important piece of the code for this file:



#define CREATE_TABLE 
" CREATE TABLE IF NOT EXISTS Fish_Table"
" (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL"
", name TEXT NOT NULL"
", image TEXT NOT NULL"
", dataDataBase BLOB NOT NULL"
", dateTime DOUBLE NOT NULL)"

dataBase::dataBase(QObject *parent)
: QObject(parent)
{
}

bool dataBase::inizializationDataBase(const QString &nameDataBase) {
// code
}

bool dataBase::addItem(const Item &item) {
QSqlQuery q;
q.prepare("INSERT INTO Fish_Table (name, image, dataDatabase, dateTime) VALUES (?,?,?,?)");
q.addBindValue(item.name());
q.addBindValue(item.image());
q.addBindValue(item.imagesData());
q.addBindValue(item.dateTime());
bool ok = q.exec();
if (!ok) {
mError = q.lastError().text();
}
return ok;
}


and finally the AddItemDialog.h and AddItemDialog.cpp that contains the fields I am trying to pass to the QTableView of the MainWindow.



AddItemDialog.h



namespace Ui
{
class AddItemDialog;
}

class AddItemDialog : public QDialog
{
Q_OBJECT
public:
explicit AddItemDialog(QWidget *parent = nullptr);
~AddItemDialog();
Item item() const { return mItem; }
private slots:
void on_toolButton_clicked();
void on_buttonBox_accepted();
void on_buttonBox_rejected();
private:
Ui::AddItemDialog *ui;
Item mItem;
};


AddItemDialog.cpp



AddItemDialog::AddItemDialog(QWidget *parent)
: QDialog(parent)
, ui(new Ui::AddItemDialog)
{
ui->setupUi(this);
auto fileSystemModel = new QFileSystemModel(this);
fileSystemModel->setRootPath(QDir::rootPath());
ui->imageLineEdit->setCompleter(new QCompleter(fileSystemModel,this));
QDateTime dateTime;
dateTime.setDate(QDate::currentDate());
}

AddItemDialog::~AddItemDialog()
{
delete ui;
}

void AddItemDialog::on_toolButton_clicked()
{
auto nameDataBase = QFileDialog::getOpenFileName(this, "Open Images", QDir::rootPath(),
"Images (*.png *.jpg *jpeg *.tif *.tiff);;Any type (*.*)");
ui->imageLineEdit->setText(nameDataBase);
}

void AddItemDialog::on_buttonBox_accepted()
{
QFile dataBase(ui->imageLineEdit->text());
if (!dataBase.open(QIODevice::ReadOnly)) {
QMessageBox::critical(this, "Error", dataBase.errorString());
return;
}
mItem = Item(ui->nameLineEdit->text(),
ui->ImLineEdit->text(),dataBase.readAll());
dataBase.close();
accept();
}


So to recap:




  1. I am not sure I provided the right format to the QDateTime conversion on the Item.h / Item.cpp and database.h / database.cpp


  2. I am not sure how to pass the QDateTime from the AddItemDialog.cpp to the MainWindow



Additionally on the AddItemDialog.cpp I am having the following error right on the beginning:
Constructor for AddItemDialog must explicitly initialize the member mItem which does not have a default constructor



Thanks for providing information on this issue that I have been having for a couple of days.










share|improve this question

























  • What database are you using?

    – eyllanesc
    Nov 25 '18 at 19:56











  • hi eyllanesc, I am using QSQLITE

    – Emanuele
    Nov 25 '18 at 20:13











  • you could share your .ui or better your project through github

    – eyllanesc
    Nov 25 '18 at 20:16











  • is it ok if I pass you my Bitbucket?

    – Emanuele
    Nov 25 '18 at 20:20











  • pass me the link of your project

    – eyllanesc
    Nov 25 '18 at 20:26














2












2








2








I am designing a major user interface with several fields and functions.
However in order to shrink the problem I created a small application with 4 columns: name, image, dataDatabase, dateTime.



I have a MainWindow with a QTableView, as soon as I right click inside the QTableView an AddItemDialog opens up with:




  1. nameLineEdit

  2. ImLineEdit

  3. imageLineEdit

  4. dateTimeEdit


The issue that I have is that I can't find a way to accept the 4) dateTimeEdit through the AddItemDialog.



I didn't "go to slot" of the dateTimeEdit as I didn't think that I had to.
I think that I am not doing the proper conversion for the date and time but please advise on what the issue might be.



I am including the most important parts of the application below with the related description of the procedure I followed:



I created an Item with the fields item.h:



class Item
{
public:
Item(const double dateTime,
const QString &name = "", const QString &image = "",
const QByteArray &imagesData = QByteArray());
QString name() const { return mName; }
QString image() const { return mImage; }
QByteArray imagesData() const { return mImagesData; }
double dateTime() const { return mDateTime; }
private:
QString mName;
QString mImage;
QByteArray mImagesData;
double mDateTime;
};


and its related item.cpp



Item::Item(const double dateTime,
const QString &name, const QString &image,
const QByteArray &imagesData)
{
mName = name;
mImage = image;
mImagesData = imagesData;
mDateTime = dateTime;
}


I created a database.h table that will contain the parameters as follows:



class dataBase : public QObject
{
Q_OBJECT
public:
explicit dataBase(QObject *parent = nullptr);
bool inizializationDataBase(const QString &nameDataBase);
bool configureDataBase();
QString getError() const { return mError; }
bool addItem(const Item &item);
private:
QSqlDatabase mDatabase;
QString mError;
};


And its related database.cpp file - I am only including the most important piece of the code for this file:



#define CREATE_TABLE 
" CREATE TABLE IF NOT EXISTS Fish_Table"
" (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL"
", name TEXT NOT NULL"
", image TEXT NOT NULL"
", dataDataBase BLOB NOT NULL"
", dateTime DOUBLE NOT NULL)"

dataBase::dataBase(QObject *parent)
: QObject(parent)
{
}

bool dataBase::inizializationDataBase(const QString &nameDataBase) {
// code
}

bool dataBase::addItem(const Item &item) {
QSqlQuery q;
q.prepare("INSERT INTO Fish_Table (name, image, dataDatabase, dateTime) VALUES (?,?,?,?)");
q.addBindValue(item.name());
q.addBindValue(item.image());
q.addBindValue(item.imagesData());
q.addBindValue(item.dateTime());
bool ok = q.exec();
if (!ok) {
mError = q.lastError().text();
}
return ok;
}


and finally the AddItemDialog.h and AddItemDialog.cpp that contains the fields I am trying to pass to the QTableView of the MainWindow.



AddItemDialog.h



namespace Ui
{
class AddItemDialog;
}

class AddItemDialog : public QDialog
{
Q_OBJECT
public:
explicit AddItemDialog(QWidget *parent = nullptr);
~AddItemDialog();
Item item() const { return mItem; }
private slots:
void on_toolButton_clicked();
void on_buttonBox_accepted();
void on_buttonBox_rejected();
private:
Ui::AddItemDialog *ui;
Item mItem;
};


AddItemDialog.cpp



AddItemDialog::AddItemDialog(QWidget *parent)
: QDialog(parent)
, ui(new Ui::AddItemDialog)
{
ui->setupUi(this);
auto fileSystemModel = new QFileSystemModel(this);
fileSystemModel->setRootPath(QDir::rootPath());
ui->imageLineEdit->setCompleter(new QCompleter(fileSystemModel,this));
QDateTime dateTime;
dateTime.setDate(QDate::currentDate());
}

AddItemDialog::~AddItemDialog()
{
delete ui;
}

void AddItemDialog::on_toolButton_clicked()
{
auto nameDataBase = QFileDialog::getOpenFileName(this, "Open Images", QDir::rootPath(),
"Images (*.png *.jpg *jpeg *.tif *.tiff);;Any type (*.*)");
ui->imageLineEdit->setText(nameDataBase);
}

void AddItemDialog::on_buttonBox_accepted()
{
QFile dataBase(ui->imageLineEdit->text());
if (!dataBase.open(QIODevice::ReadOnly)) {
QMessageBox::critical(this, "Error", dataBase.errorString());
return;
}
mItem = Item(ui->nameLineEdit->text(),
ui->ImLineEdit->text(),dataBase.readAll());
dataBase.close();
accept();
}


So to recap:




  1. I am not sure I provided the right format to the QDateTime conversion on the Item.h / Item.cpp and database.h / database.cpp


  2. I am not sure how to pass the QDateTime from the AddItemDialog.cpp to the MainWindow



Additionally on the AddItemDialog.cpp I am having the following error right on the beginning:
Constructor for AddItemDialog must explicitly initialize the member mItem which does not have a default constructor



Thanks for providing information on this issue that I have been having for a couple of days.










share|improve this question
















I am designing a major user interface with several fields and functions.
However in order to shrink the problem I created a small application with 4 columns: name, image, dataDatabase, dateTime.



I have a MainWindow with a QTableView, as soon as I right click inside the QTableView an AddItemDialog opens up with:




  1. nameLineEdit

  2. ImLineEdit

  3. imageLineEdit

  4. dateTimeEdit


The issue that I have is that I can't find a way to accept the 4) dateTimeEdit through the AddItemDialog.



I didn't "go to slot" of the dateTimeEdit as I didn't think that I had to.
I think that I am not doing the proper conversion for the date and time but please advise on what the issue might be.



I am including the most important parts of the application below with the related description of the procedure I followed:



I created an Item with the fields item.h:



class Item
{
public:
Item(const double dateTime,
const QString &name = "", const QString &image = "",
const QByteArray &imagesData = QByteArray());
QString name() const { return mName; }
QString image() const { return mImage; }
QByteArray imagesData() const { return mImagesData; }
double dateTime() const { return mDateTime; }
private:
QString mName;
QString mImage;
QByteArray mImagesData;
double mDateTime;
};


and its related item.cpp



Item::Item(const double dateTime,
const QString &name, const QString &image,
const QByteArray &imagesData)
{
mName = name;
mImage = image;
mImagesData = imagesData;
mDateTime = dateTime;
}


I created a database.h table that will contain the parameters as follows:



class dataBase : public QObject
{
Q_OBJECT
public:
explicit dataBase(QObject *parent = nullptr);
bool inizializationDataBase(const QString &nameDataBase);
bool configureDataBase();
QString getError() const { return mError; }
bool addItem(const Item &item);
private:
QSqlDatabase mDatabase;
QString mError;
};


And its related database.cpp file - I am only including the most important piece of the code for this file:



#define CREATE_TABLE 
" CREATE TABLE IF NOT EXISTS Fish_Table"
" (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL"
", name TEXT NOT NULL"
", image TEXT NOT NULL"
", dataDataBase BLOB NOT NULL"
", dateTime DOUBLE NOT NULL)"

dataBase::dataBase(QObject *parent)
: QObject(parent)
{
}

bool dataBase::inizializationDataBase(const QString &nameDataBase) {
// code
}

bool dataBase::addItem(const Item &item) {
QSqlQuery q;
q.prepare("INSERT INTO Fish_Table (name, image, dataDatabase, dateTime) VALUES (?,?,?,?)");
q.addBindValue(item.name());
q.addBindValue(item.image());
q.addBindValue(item.imagesData());
q.addBindValue(item.dateTime());
bool ok = q.exec();
if (!ok) {
mError = q.lastError().text();
}
return ok;
}


and finally the AddItemDialog.h and AddItemDialog.cpp that contains the fields I am trying to pass to the QTableView of the MainWindow.



AddItemDialog.h



namespace Ui
{
class AddItemDialog;
}

class AddItemDialog : public QDialog
{
Q_OBJECT
public:
explicit AddItemDialog(QWidget *parent = nullptr);
~AddItemDialog();
Item item() const { return mItem; }
private slots:
void on_toolButton_clicked();
void on_buttonBox_accepted();
void on_buttonBox_rejected();
private:
Ui::AddItemDialog *ui;
Item mItem;
};


AddItemDialog.cpp



AddItemDialog::AddItemDialog(QWidget *parent)
: QDialog(parent)
, ui(new Ui::AddItemDialog)
{
ui->setupUi(this);
auto fileSystemModel = new QFileSystemModel(this);
fileSystemModel->setRootPath(QDir::rootPath());
ui->imageLineEdit->setCompleter(new QCompleter(fileSystemModel,this));
QDateTime dateTime;
dateTime.setDate(QDate::currentDate());
}

AddItemDialog::~AddItemDialog()
{
delete ui;
}

void AddItemDialog::on_toolButton_clicked()
{
auto nameDataBase = QFileDialog::getOpenFileName(this, "Open Images", QDir::rootPath(),
"Images (*.png *.jpg *jpeg *.tif *.tiff);;Any type (*.*)");
ui->imageLineEdit->setText(nameDataBase);
}

void AddItemDialog::on_buttonBox_accepted()
{
QFile dataBase(ui->imageLineEdit->text());
if (!dataBase.open(QIODevice::ReadOnly)) {
QMessageBox::critical(this, "Error", dataBase.errorString());
return;
}
mItem = Item(ui->nameLineEdit->text(),
ui->ImLineEdit->text(),dataBase.readAll());
dataBase.close();
accept();
}


So to recap:




  1. I am not sure I provided the right format to the QDateTime conversion on the Item.h / Item.cpp and database.h / database.cpp


  2. I am not sure how to pass the QDateTime from the AddItemDialog.cpp to the MainWindow



Additionally on the AddItemDialog.cpp I am having the following error right on the beginning:
Constructor for AddItemDialog must explicitly initialize the member mItem which does not have a default constructor



Thanks for providing information on this issue that I have been having for a couple of days.







qt c++11 qt5 qt4






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 25 '18 at 19:58









eyllanesc

77.3k103156




77.3k103156










asked Nov 25 '18 at 19:46









EmanueleEmanuele

316




316













  • What database are you using?

    – eyllanesc
    Nov 25 '18 at 19:56











  • hi eyllanesc, I am using QSQLITE

    – Emanuele
    Nov 25 '18 at 20:13











  • you could share your .ui or better your project through github

    – eyllanesc
    Nov 25 '18 at 20:16











  • is it ok if I pass you my Bitbucket?

    – Emanuele
    Nov 25 '18 at 20:20











  • pass me the link of your project

    – eyllanesc
    Nov 25 '18 at 20:26



















  • What database are you using?

    – eyllanesc
    Nov 25 '18 at 19:56











  • hi eyllanesc, I am using QSQLITE

    – Emanuele
    Nov 25 '18 at 20:13











  • you could share your .ui or better your project through github

    – eyllanesc
    Nov 25 '18 at 20:16











  • is it ok if I pass you my Bitbucket?

    – Emanuele
    Nov 25 '18 at 20:20











  • pass me the link of your project

    – eyllanesc
    Nov 25 '18 at 20:26

















What database are you using?

– eyllanesc
Nov 25 '18 at 19:56





What database are you using?

– eyllanesc
Nov 25 '18 at 19:56













hi eyllanesc, I am using QSQLITE

– Emanuele
Nov 25 '18 at 20:13





hi eyllanesc, I am using QSQLITE

– Emanuele
Nov 25 '18 at 20:13













you could share your .ui or better your project through github

– eyllanesc
Nov 25 '18 at 20:16





you could share your .ui or better your project through github

– eyllanesc
Nov 25 '18 at 20:16













is it ok if I pass you my Bitbucket?

– Emanuele
Nov 25 '18 at 20:20





is it ok if I pass you my Bitbucket?

– Emanuele
Nov 25 '18 at 20:20













pass me the link of your project

– eyllanesc
Nov 25 '18 at 20:26





pass me the link of your project

– eyllanesc
Nov 25 '18 at 20:26












1 Answer
1






active

oldest

votes


















1














Use DATETIME as a field and use QDateTime directly:



#define CREATE_TABLE 
" CREATE TABLE IF NOT EXISTS Fish_Table"
" (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL"
", name TEXT NOT NULL"
", image TEXT NOT NULL"
", dataDataBase BLOB NOT NULL"
", dateTime DATETIME NOT NULL)" /// <---


Then change item:



item.h



#ifndef ITEM_H
#define ITEM_H
#include <QDateTime>
#include <QString>

class Item
{
public:
Item(const QDateTime & dateTime=QDateTime::currentDateTime(),
const QString &name = "", const QString &image = "",
const QByteArray &imagesData = QByteArray());
QString name() const { return mName; }
QString image() const { return mImage; }
QByteArray imagesData() const { return mImagesData; }
QDateTime dateTime() const { return mDateTime; }
private:
QString mName;
QString mImage;
QByteArray mImagesData;
QDateTime mDateTime;
};

#endif // ITEM_H


item.cpp



#include "item.h"

Item::Item(const QDateTime &dateTime,
const QString &name, const QString &image,
const QByteArray &imagesData):
mName(name),
mImage(image),
mImagesData(imagesData),
mDateTime(dateTime)
{
}


And then you pass the QDateTime directly as indicated:



void AddItemDialog::on_buttonBox_accepted()
{
QFile dataBase(ui->imageLineEdit->text());
if (!dataBase.open(QIODevice::ReadOnly)) {
QMessageBox::critical(this, "Error", dataBase.errorString());
return;
}
mItem = Item(ui->dateTimeEdit->dateTime(),
ui->nameLineEdit->text(),
ui->ImLineEdit->text(),
dataBase.readAll());
dataBase.close();
accept();
}





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53471228%2fqdatetime-not-accepted-by-qtableview%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Use DATETIME as a field and use QDateTime directly:



    #define CREATE_TABLE 
    " CREATE TABLE IF NOT EXISTS Fish_Table"
    " (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL"
    ", name TEXT NOT NULL"
    ", image TEXT NOT NULL"
    ", dataDataBase BLOB NOT NULL"
    ", dateTime DATETIME NOT NULL)" /// <---


    Then change item:



    item.h



    #ifndef ITEM_H
    #define ITEM_H
    #include <QDateTime>
    #include <QString>

    class Item
    {
    public:
    Item(const QDateTime & dateTime=QDateTime::currentDateTime(),
    const QString &name = "", const QString &image = "",
    const QByteArray &imagesData = QByteArray());
    QString name() const { return mName; }
    QString image() const { return mImage; }
    QByteArray imagesData() const { return mImagesData; }
    QDateTime dateTime() const { return mDateTime; }
    private:
    QString mName;
    QString mImage;
    QByteArray mImagesData;
    QDateTime mDateTime;
    };

    #endif // ITEM_H


    item.cpp



    #include "item.h"

    Item::Item(const QDateTime &dateTime,
    const QString &name, const QString &image,
    const QByteArray &imagesData):
    mName(name),
    mImage(image),
    mImagesData(imagesData),
    mDateTime(dateTime)
    {
    }


    And then you pass the QDateTime directly as indicated:



    void AddItemDialog::on_buttonBox_accepted()
    {
    QFile dataBase(ui->imageLineEdit->text());
    if (!dataBase.open(QIODevice::ReadOnly)) {
    QMessageBox::critical(this, "Error", dataBase.errorString());
    return;
    }
    mItem = Item(ui->dateTimeEdit->dateTime(),
    ui->nameLineEdit->text(),
    ui->ImLineEdit->text(),
    dataBase.readAll());
    dataBase.close();
    accept();
    }





    share|improve this answer




























      1














      Use DATETIME as a field and use QDateTime directly:



      #define CREATE_TABLE 
      " CREATE TABLE IF NOT EXISTS Fish_Table"
      " (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL"
      ", name TEXT NOT NULL"
      ", image TEXT NOT NULL"
      ", dataDataBase BLOB NOT NULL"
      ", dateTime DATETIME NOT NULL)" /// <---


      Then change item:



      item.h



      #ifndef ITEM_H
      #define ITEM_H
      #include <QDateTime>
      #include <QString>

      class Item
      {
      public:
      Item(const QDateTime & dateTime=QDateTime::currentDateTime(),
      const QString &name = "", const QString &image = "",
      const QByteArray &imagesData = QByteArray());
      QString name() const { return mName; }
      QString image() const { return mImage; }
      QByteArray imagesData() const { return mImagesData; }
      QDateTime dateTime() const { return mDateTime; }
      private:
      QString mName;
      QString mImage;
      QByteArray mImagesData;
      QDateTime mDateTime;
      };

      #endif // ITEM_H


      item.cpp



      #include "item.h"

      Item::Item(const QDateTime &dateTime,
      const QString &name, const QString &image,
      const QByteArray &imagesData):
      mName(name),
      mImage(image),
      mImagesData(imagesData),
      mDateTime(dateTime)
      {
      }


      And then you pass the QDateTime directly as indicated:



      void AddItemDialog::on_buttonBox_accepted()
      {
      QFile dataBase(ui->imageLineEdit->text());
      if (!dataBase.open(QIODevice::ReadOnly)) {
      QMessageBox::critical(this, "Error", dataBase.errorString());
      return;
      }
      mItem = Item(ui->dateTimeEdit->dateTime(),
      ui->nameLineEdit->text(),
      ui->ImLineEdit->text(),
      dataBase.readAll());
      dataBase.close();
      accept();
      }





      share|improve this answer


























        1












        1








        1







        Use DATETIME as a field and use QDateTime directly:



        #define CREATE_TABLE 
        " CREATE TABLE IF NOT EXISTS Fish_Table"
        " (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL"
        ", name TEXT NOT NULL"
        ", image TEXT NOT NULL"
        ", dataDataBase BLOB NOT NULL"
        ", dateTime DATETIME NOT NULL)" /// <---


        Then change item:



        item.h



        #ifndef ITEM_H
        #define ITEM_H
        #include <QDateTime>
        #include <QString>

        class Item
        {
        public:
        Item(const QDateTime & dateTime=QDateTime::currentDateTime(),
        const QString &name = "", const QString &image = "",
        const QByteArray &imagesData = QByteArray());
        QString name() const { return mName; }
        QString image() const { return mImage; }
        QByteArray imagesData() const { return mImagesData; }
        QDateTime dateTime() const { return mDateTime; }
        private:
        QString mName;
        QString mImage;
        QByteArray mImagesData;
        QDateTime mDateTime;
        };

        #endif // ITEM_H


        item.cpp



        #include "item.h"

        Item::Item(const QDateTime &dateTime,
        const QString &name, const QString &image,
        const QByteArray &imagesData):
        mName(name),
        mImage(image),
        mImagesData(imagesData),
        mDateTime(dateTime)
        {
        }


        And then you pass the QDateTime directly as indicated:



        void AddItemDialog::on_buttonBox_accepted()
        {
        QFile dataBase(ui->imageLineEdit->text());
        if (!dataBase.open(QIODevice::ReadOnly)) {
        QMessageBox::critical(this, "Error", dataBase.errorString());
        return;
        }
        mItem = Item(ui->dateTimeEdit->dateTime(),
        ui->nameLineEdit->text(),
        ui->ImLineEdit->text(),
        dataBase.readAll());
        dataBase.close();
        accept();
        }





        share|improve this answer













        Use DATETIME as a field and use QDateTime directly:



        #define CREATE_TABLE 
        " CREATE TABLE IF NOT EXISTS Fish_Table"
        " (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL"
        ", name TEXT NOT NULL"
        ", image TEXT NOT NULL"
        ", dataDataBase BLOB NOT NULL"
        ", dateTime DATETIME NOT NULL)" /// <---


        Then change item:



        item.h



        #ifndef ITEM_H
        #define ITEM_H
        #include <QDateTime>
        #include <QString>

        class Item
        {
        public:
        Item(const QDateTime & dateTime=QDateTime::currentDateTime(),
        const QString &name = "", const QString &image = "",
        const QByteArray &imagesData = QByteArray());
        QString name() const { return mName; }
        QString image() const { return mImage; }
        QByteArray imagesData() const { return mImagesData; }
        QDateTime dateTime() const { return mDateTime; }
        private:
        QString mName;
        QString mImage;
        QByteArray mImagesData;
        QDateTime mDateTime;
        };

        #endif // ITEM_H


        item.cpp



        #include "item.h"

        Item::Item(const QDateTime &dateTime,
        const QString &name, const QString &image,
        const QByteArray &imagesData):
        mName(name),
        mImage(image),
        mImagesData(imagesData),
        mDateTime(dateTime)
        {
        }


        And then you pass the QDateTime directly as indicated:



        void AddItemDialog::on_buttonBox_accepted()
        {
        QFile dataBase(ui->imageLineEdit->text());
        if (!dataBase.open(QIODevice::ReadOnly)) {
        QMessageBox::critical(this, "Error", dataBase.errorString());
        return;
        }
        mItem = Item(ui->dateTimeEdit->dateTime(),
        ui->nameLineEdit->text(),
        ui->ImLineEdit->text(),
        dataBase.readAll());
        dataBase.close();
        accept();
        }






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 25 '18 at 22:04









        eyllanesceyllanesc

        77.3k103156




        77.3k103156






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53471228%2fqdatetime-not-accepted-by-qtableview%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

            Calculate evaluation metrics using cross_val_predict sklearn

            Insert data from modal to MySQL (multiple modal on website)