QSqlTableModel and QSQLITE not showing correct columns & headerQSqlDatabase: How to avoid 'qt_sql_default_connection' still in use & duplicate connection related warning?Add a column with a default value to an existing table in SQL ServerHow can I SELECT rows with MAX(Column value), DISTINCT by another column in SQL?SQL multiple column orderingUsing group by on multiple columnsFind all tables containing column with specified name - MS SQL Server'IF' in 'SELECT' statement - choose output value based on column valuesSQL select only rows with max value on a columnRename column SQL Server 2008Show image in a column of QTableView from QSqlTableModelHow to erase QSQLITE reference index linked to QGraphicsItem from a QTableView
How would vampires avoid contracting diseases?
How can I truly shut down ssh server?
Are neural networks prone to catastrophic forgetting?
Is anyone advocating the promotion of homosexuality in UK schools?
Keep milk (or milk alternative) for a day without a fridge
Received a dinner invitation through my employer's email, is it ok to attend?
How do you glue a text to a point?
How to convert a file with several spaces into a tab-delimited file?
Does Lufthansa weigh your carry on luggage?
What prevents someone from claiming to be the murderer in order to get the real murderer off?
Storming Area 51
How do you move up one folder in Finder?
Why are all my yellow 2V/20mA LEDs burning out with 330k Ohm resistor?
Is there any word for "disobedience to God"?
Was I subtly told to resign?
Print the last, middle and first character of your code
Use of って when quotation doesn't make sense
How to loop for 3 times in bash script when docker push fails?
During copyediting, journal disagrees about spelling of paper's main topic
Contexte et orthographe du mot « feedback »
Are randomly-generated passwords starting with "a" less secure?
Did the Vulgar Latin verb "toccare" exist?
Why can a destructor change the state of a constant object?
Do you know your 'KVZ's?
QSqlTableModel and QSQLITE not showing correct columns & header
QSqlDatabase: How to avoid 'qt_sql_default_connection' still in use & duplicate connection related warning?Add a column with a default value to an existing table in SQL ServerHow can I SELECT rows with MAX(Column value), DISTINCT by another column in SQL?SQL multiple column orderingUsing group by on multiple columnsFind all tables containing column with specified name - MS SQL Server'IF' in 'SELECT' statement - choose output value based on column valuesSQL select only rows with max value on a columnRename column SQL Server 2008Show image in a column of QTableView from QSqlTableModelHow to erase QSQLITE reference index linked to QGraphicsItem from a QTableView
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
On a user interface I have a QTableView that looks like this at the very beginning after first start:

As soon as the user run the project and create a new database .db (say the user puts the .db file on the Desktop), this QTableView looks like this which the correct behavior:

The problem: After I start saving images and their path all the headers carries different names (1,2,3,4) instead of (path1, path2, image1, image2) as shown previously and there is an id column missing, like this below which is the wrong behavior:

Below is how I am setting the most important parameters:
mainwindow.h
private:
QString temporaryFolder;
dataInfo *mNewDatabaseImages;
QSqlTableModel *mNewTableImages;
QStandardItemModel *model;
mainwindow.cpp
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
ui->setupUi(this);
temporaryFolder = "/home/path/toDesktop/folder/a.db";
QFile dbRem(temporaryFolder);
dbRem.remove();
mNewDatabaseImages = new dataInfo(this);
mNewDatabaseImages->initDataBase(temporaryFolder);
mNewDatabaseImages->confDataBase();
mNewTableImages = new QSqlTableModel(this, mNewDatabaseImages->getDatabase());
mNewTableImages->setTable("imageTable");
mNewTableImages->select();
ui->bookMarkTableView->setModel(mNewTableImages);
model = new QStandardItemModel();
ui->bookMarkTableView->setModel(model);
ui->bookMarkTableView->showColumn(true);
In addition to that there are two icons on the user interface with which I open an existing database or I create a new database as it is possible to see below:

This part is on the mainwindow.cpp too and below is the snipped of code:
void MainWindow::openDatabase(MainWindow::Opening opening)
QString nameDatabase;
if(opening == OPENING)
nameDatabase = QFileDialog::getOpenFileName(this,
"Open Database", QDir::rootPath(),
"Database (*.db);;Any type (*.*)");
else
nameDatabase = QFileDialog::getSaveFileName(this,
"New Database", QDir::rootPath(),
"Database (*.db);;Any type (*.*)");
if(nameDatabase.isEmpty())
return;
if(!mNewDatabaseImages->initDataBase(nameDatabase))
QMessageBox::critical(this, "Error", mNewDatabaseImages->getError());
return;
if(!mNewDatabaseImages->confDataBase())
QMessageBox::critical(this, "Error", mNewDatabaseImages->getError());
return;
delete mNewTableImages;
// Work with the database file created
mNewTableImages = new QSqlTableModel(this, mNewDatabaseImages->getDatabase());
mNewTableImages->setTable("imageTable");
mNewTableImages->select();
ui->bookMarkTableView->setModel(mNewTableImages);
ui->bookMarkTableView->showColumn(true);
The database I am using is QSQLITE and the way the SQL is written is here if there is any need to see the snipped of that too.
Why does QTableView is not showing the correct headers and columns?
Thanks for pointing in the right direction.
sql c++11 sqlite qt5 qtableview
add a comment |
On a user interface I have a QTableView that looks like this at the very beginning after first start:

As soon as the user run the project and create a new database .db (say the user puts the .db file on the Desktop), this QTableView looks like this which the correct behavior:

The problem: After I start saving images and their path all the headers carries different names (1,2,3,4) instead of (path1, path2, image1, image2) as shown previously and there is an id column missing, like this below which is the wrong behavior:

Below is how I am setting the most important parameters:
mainwindow.h
private:
QString temporaryFolder;
dataInfo *mNewDatabaseImages;
QSqlTableModel *mNewTableImages;
QStandardItemModel *model;
mainwindow.cpp
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
ui->setupUi(this);
temporaryFolder = "/home/path/toDesktop/folder/a.db";
QFile dbRem(temporaryFolder);
dbRem.remove();
mNewDatabaseImages = new dataInfo(this);
mNewDatabaseImages->initDataBase(temporaryFolder);
mNewDatabaseImages->confDataBase();
mNewTableImages = new QSqlTableModel(this, mNewDatabaseImages->getDatabase());
mNewTableImages->setTable("imageTable");
mNewTableImages->select();
ui->bookMarkTableView->setModel(mNewTableImages);
model = new QStandardItemModel();
ui->bookMarkTableView->setModel(model);
ui->bookMarkTableView->showColumn(true);
In addition to that there are two icons on the user interface with which I open an existing database or I create a new database as it is possible to see below:

This part is on the mainwindow.cpp too and below is the snipped of code:
void MainWindow::openDatabase(MainWindow::Opening opening)
QString nameDatabase;
if(opening == OPENING)
nameDatabase = QFileDialog::getOpenFileName(this,
"Open Database", QDir::rootPath(),
"Database (*.db);;Any type (*.*)");
else
nameDatabase = QFileDialog::getSaveFileName(this,
"New Database", QDir::rootPath(),
"Database (*.db);;Any type (*.*)");
if(nameDatabase.isEmpty())
return;
if(!mNewDatabaseImages->initDataBase(nameDatabase))
QMessageBox::critical(this, "Error", mNewDatabaseImages->getError());
return;
if(!mNewDatabaseImages->confDataBase())
QMessageBox::critical(this, "Error", mNewDatabaseImages->getError());
return;
delete mNewTableImages;
// Work with the database file created
mNewTableImages = new QSqlTableModel(this, mNewDatabaseImages->getDatabase());
mNewTableImages->setTable("imageTable");
mNewTableImages->select();
ui->bookMarkTableView->setModel(mNewTableImages);
ui->bookMarkTableView->showColumn(true);
The database I am using is QSQLITE and the way the SQL is written is here if there is any need to see the snipped of that too.
Why does QTableView is not showing the correct headers and columns?
Thanks for pointing in the right direction.
sql c++11 sqlite qt5 qtableview
add a comment |
On a user interface I have a QTableView that looks like this at the very beginning after first start:

As soon as the user run the project and create a new database .db (say the user puts the .db file on the Desktop), this QTableView looks like this which the correct behavior:

The problem: After I start saving images and their path all the headers carries different names (1,2,3,4) instead of (path1, path2, image1, image2) as shown previously and there is an id column missing, like this below which is the wrong behavior:

Below is how I am setting the most important parameters:
mainwindow.h
private:
QString temporaryFolder;
dataInfo *mNewDatabaseImages;
QSqlTableModel *mNewTableImages;
QStandardItemModel *model;
mainwindow.cpp
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
ui->setupUi(this);
temporaryFolder = "/home/path/toDesktop/folder/a.db";
QFile dbRem(temporaryFolder);
dbRem.remove();
mNewDatabaseImages = new dataInfo(this);
mNewDatabaseImages->initDataBase(temporaryFolder);
mNewDatabaseImages->confDataBase();
mNewTableImages = new QSqlTableModel(this, mNewDatabaseImages->getDatabase());
mNewTableImages->setTable("imageTable");
mNewTableImages->select();
ui->bookMarkTableView->setModel(mNewTableImages);
model = new QStandardItemModel();
ui->bookMarkTableView->setModel(model);
ui->bookMarkTableView->showColumn(true);
In addition to that there are two icons on the user interface with which I open an existing database or I create a new database as it is possible to see below:

This part is on the mainwindow.cpp too and below is the snipped of code:
void MainWindow::openDatabase(MainWindow::Opening opening)
QString nameDatabase;
if(opening == OPENING)
nameDatabase = QFileDialog::getOpenFileName(this,
"Open Database", QDir::rootPath(),
"Database (*.db);;Any type (*.*)");
else
nameDatabase = QFileDialog::getSaveFileName(this,
"New Database", QDir::rootPath(),
"Database (*.db);;Any type (*.*)");
if(nameDatabase.isEmpty())
return;
if(!mNewDatabaseImages->initDataBase(nameDatabase))
QMessageBox::critical(this, "Error", mNewDatabaseImages->getError());
return;
if(!mNewDatabaseImages->confDataBase())
QMessageBox::critical(this, "Error", mNewDatabaseImages->getError());
return;
delete mNewTableImages;
// Work with the database file created
mNewTableImages = new QSqlTableModel(this, mNewDatabaseImages->getDatabase());
mNewTableImages->setTable("imageTable");
mNewTableImages->select();
ui->bookMarkTableView->setModel(mNewTableImages);
ui->bookMarkTableView->showColumn(true);
The database I am using is QSQLITE and the way the SQL is written is here if there is any need to see the snipped of that too.
Why does QTableView is not showing the correct headers and columns?
Thanks for pointing in the right direction.
sql c++11 sqlite qt5 qtableview
On a user interface I have a QTableView that looks like this at the very beginning after first start:

As soon as the user run the project and create a new database .db (say the user puts the .db file on the Desktop), this QTableView looks like this which the correct behavior:

The problem: After I start saving images and their path all the headers carries different names (1,2,3,4) instead of (path1, path2, image1, image2) as shown previously and there is an id column missing, like this below which is the wrong behavior:

Below is how I am setting the most important parameters:
mainwindow.h
private:
QString temporaryFolder;
dataInfo *mNewDatabaseImages;
QSqlTableModel *mNewTableImages;
QStandardItemModel *model;
mainwindow.cpp
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
ui->setupUi(this);
temporaryFolder = "/home/path/toDesktop/folder/a.db";
QFile dbRem(temporaryFolder);
dbRem.remove();
mNewDatabaseImages = new dataInfo(this);
mNewDatabaseImages->initDataBase(temporaryFolder);
mNewDatabaseImages->confDataBase();
mNewTableImages = new QSqlTableModel(this, mNewDatabaseImages->getDatabase());
mNewTableImages->setTable("imageTable");
mNewTableImages->select();
ui->bookMarkTableView->setModel(mNewTableImages);
model = new QStandardItemModel();
ui->bookMarkTableView->setModel(model);
ui->bookMarkTableView->showColumn(true);
In addition to that there are two icons on the user interface with which I open an existing database or I create a new database as it is possible to see below:

This part is on the mainwindow.cpp too and below is the snipped of code:
void MainWindow::openDatabase(MainWindow::Opening opening)
QString nameDatabase;
if(opening == OPENING)
nameDatabase = QFileDialog::getOpenFileName(this,
"Open Database", QDir::rootPath(),
"Database (*.db);;Any type (*.*)");
else
nameDatabase = QFileDialog::getSaveFileName(this,
"New Database", QDir::rootPath(),
"Database (*.db);;Any type (*.*)");
if(nameDatabase.isEmpty())
return;
if(!mNewDatabaseImages->initDataBase(nameDatabase))
QMessageBox::critical(this, "Error", mNewDatabaseImages->getError());
return;
if(!mNewDatabaseImages->confDataBase())
QMessageBox::critical(this, "Error", mNewDatabaseImages->getError());
return;
delete mNewTableImages;
// Work with the database file created
mNewTableImages = new QSqlTableModel(this, mNewDatabaseImages->getDatabase());
mNewTableImages->setTable("imageTable");
mNewTableImages->select();
ui->bookMarkTableView->setModel(mNewTableImages);
ui->bookMarkTableView->showColumn(true);
The database I am using is QSQLITE and the way the SQL is written is here if there is any need to see the snipped of that too.
Why does QTableView is not showing the correct headers and columns?
Thanks for pointing in the right direction.
sql c++11 sqlite qt5 qtableview
sql c++11 sqlite qt5 qtableview
asked Mar 26 at 2:17
EmanueleEmanuele
3442 silver badges15 bronze badges
3442 silver badges15 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
That is because you are overwriting it with a new QStandardItemModel, therefore every time the program runs all the headers disappears. Try to modify your constructor by commenting out the last three lines in the following way:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
ui->setupUi(this);
temporaryFolder = "/home/path/toDesktop/folder/a.db";
QFile dbRem(temporaryFolder);
dbRem.remove();
mNewDatabaseImages = new dataInfo(this);
mNewDatabaseImages->initDataBase(temporaryFolder);
mNewDatabaseImages->confDataBase();
mNewTableImages = new QSqlTableModel(this, mNewDatabaseImages->getDatabase());
mNewTableImages->setTable("imageTable");
mNewTableImages->select();
ui->bookMarkTableView->setModel(mNewTableImages);
// In this way you don't overwrite your initial headers
// model = new QStandardItemModel();
// ui->bookMarkTableView->setModel(model);
// ui->bookMarkTableView->showColumn(true);
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55348935%2fqsqltablemodel-and-qsqlite-not-showing-correct-columns-header%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
That is because you are overwriting it with a new QStandardItemModel, therefore every time the program runs all the headers disappears. Try to modify your constructor by commenting out the last three lines in the following way:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
ui->setupUi(this);
temporaryFolder = "/home/path/toDesktop/folder/a.db";
QFile dbRem(temporaryFolder);
dbRem.remove();
mNewDatabaseImages = new dataInfo(this);
mNewDatabaseImages->initDataBase(temporaryFolder);
mNewDatabaseImages->confDataBase();
mNewTableImages = new QSqlTableModel(this, mNewDatabaseImages->getDatabase());
mNewTableImages->setTable("imageTable");
mNewTableImages->select();
ui->bookMarkTableView->setModel(mNewTableImages);
// In this way you don't overwrite your initial headers
// model = new QStandardItemModel();
// ui->bookMarkTableView->setModel(model);
// ui->bookMarkTableView->showColumn(true);
add a comment |
That is because you are overwriting it with a new QStandardItemModel, therefore every time the program runs all the headers disappears. Try to modify your constructor by commenting out the last three lines in the following way:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
ui->setupUi(this);
temporaryFolder = "/home/path/toDesktop/folder/a.db";
QFile dbRem(temporaryFolder);
dbRem.remove();
mNewDatabaseImages = new dataInfo(this);
mNewDatabaseImages->initDataBase(temporaryFolder);
mNewDatabaseImages->confDataBase();
mNewTableImages = new QSqlTableModel(this, mNewDatabaseImages->getDatabase());
mNewTableImages->setTable("imageTable");
mNewTableImages->select();
ui->bookMarkTableView->setModel(mNewTableImages);
// In this way you don't overwrite your initial headers
// model = new QStandardItemModel();
// ui->bookMarkTableView->setModel(model);
// ui->bookMarkTableView->showColumn(true);
add a comment |
That is because you are overwriting it with a new QStandardItemModel, therefore every time the program runs all the headers disappears. Try to modify your constructor by commenting out the last three lines in the following way:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
ui->setupUi(this);
temporaryFolder = "/home/path/toDesktop/folder/a.db";
QFile dbRem(temporaryFolder);
dbRem.remove();
mNewDatabaseImages = new dataInfo(this);
mNewDatabaseImages->initDataBase(temporaryFolder);
mNewDatabaseImages->confDataBase();
mNewTableImages = new QSqlTableModel(this, mNewDatabaseImages->getDatabase());
mNewTableImages->setTable("imageTable");
mNewTableImages->select();
ui->bookMarkTableView->setModel(mNewTableImages);
// In this way you don't overwrite your initial headers
// model = new QStandardItemModel();
// ui->bookMarkTableView->setModel(model);
// ui->bookMarkTableView->showColumn(true);
That is because you are overwriting it with a new QStandardItemModel, therefore every time the program runs all the headers disappears. Try to modify your constructor by commenting out the last three lines in the following way:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
ui->setupUi(this);
temporaryFolder = "/home/path/toDesktop/folder/a.db";
QFile dbRem(temporaryFolder);
dbRem.remove();
mNewDatabaseImages = new dataInfo(this);
mNewDatabaseImages->initDataBase(temporaryFolder);
mNewDatabaseImages->confDataBase();
mNewTableImages = new QSqlTableModel(this, mNewDatabaseImages->getDatabase());
mNewTableImages->setTable("imageTable");
mNewTableImages->select();
ui->bookMarkTableView->setModel(mNewTableImages);
// In this way you don't overwrite your initial headers
// model = new QStandardItemModel();
// ui->bookMarkTableView->setModel(model);
// ui->bookMarkTableView->showColumn(true);
answered Mar 26 at 14:05
user10826999
add a comment |
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55348935%2fqsqltablemodel-and-qsqlite-not-showing-correct-columns-header%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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