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;








0















On a user interface I have a QTableView that looks like this at the very beginning after first start:



QTableView



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:



Correct_QTableView



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:



wrong



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:



icons



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.










share|improve this question




























    0















    On a user interface I have a QTableView that looks like this at the very beginning after first start:



    QTableView



    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:



    Correct_QTableView



    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:



    wrong



    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:



    icons



    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.










    share|improve this question
























      0












      0








      0








      On a user interface I have a QTableView that looks like this at the very beginning after first start:



      QTableView



      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:



      Correct_QTableView



      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:



      wrong



      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:



      icons



      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.










      share|improve this question














      On a user interface I have a QTableView that looks like this at the very beginning after first start:



      QTableView



      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:



      Correct_QTableView



      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:



      wrong



      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:



      icons



      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 26 at 2:17









      EmanueleEmanuele

      3442 silver badges15 bronze badges




      3442 silver badges15 bronze badges






















          1 Answer
          1






          active

          oldest

          votes


















          0














          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);






          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%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









            0














            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);






            share|improve this answer



























              0














              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);






              share|improve this answer

























                0












                0








                0







                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);






                share|improve this answer













                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);







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 26 at 14:05







                user10826999

























                    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.



















                    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%2f55348935%2fqsqltablemodel-and-qsqlite-not-showing-correct-columns-header%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

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

                    155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해