Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSqlQueryModel and QTableView closes program.
Forum Updated to NodeBB v4.3 + New Features

QSqlQueryModel and QTableView closes program.

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 2.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    A.J. Hwang
    wrote on last edited by
    #1

    Hello, I'm new in QT.

    I made program like below::
    @
    queryString = "SELECT " + queryField + " FROM partiRegi WHERE " + queryField + " LIKE '%" + searchText + "%'";
    QSqlQueryModel *searchModel = new QSqlQueryModel;
    searchModel->setQuery(queryString);
    searchModel->setHeaderData(0, Qt::Horizontal, tr("Result"));

    searchResultView = new QTableView;
    searchResultView->setModel(searchModel);
    searchResultView->setSelectionBehavior(QAbstractItemView::SelectRows);
    searchResultView->setSelectionMode(QAbstractItemView::SingleSelection);
    searchResultView->horizontalHeader()->setStretchLastSection(true);
    
    
    QVBoxLayout *layout = new QVBoxLayout;
    layout->addWidget(searchResultView);
    searchResultPanel->setLayout(layout);
    

    @
    Everytime "searchText" changed I delete "searchResultPanel" and re-layout it.

    I had succeed using this with QSqlRelationalTableModel + QTableView.

    But when I click in QSqlQueryModel + QTableView, program closes with error.

    "debug\WithoutUI.exe exited with code -1073741819"

    Can anybody tell me what is the problem??

    Edit: please use @ tags around your code sections; Andre

    1 Reply Last reply
    0
    • JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      Are you using QtCreator? If so, run the debugger (Top menu: Debug -> Start debugging -> Start debugging). Then, when it crashes, you debugger can show you what triggered the problem.

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      0
      • A Offline
        A Offline
        A.J. Hwang
        wrote on last edited by
        #3

        Thank you JKSH.

        I run the debugger and pop-up says

        "Signal received
        The inferior stopped because it received a signal from the OS.
        Signal Name : SIGSEGV
        Signal meaning : Segmentation fault."

        What this means??

        When I did FindAll and click in the QTableView it does not go wrong.

        Is there some error in query or TableView??

        1 Reply Last reply
        0
        • JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #4

          You're welcome.

          You get a "segmentation fault" if your program tries to read or write memory that it is not allowed to access. For example, if you delete searchResultPanel, and you don't construct a new Panel, but you still call searchResultPanel->setLayout(), this error will occur. I can't see anything wrong in the code you posted, so the error begins somewhere else.

          Go back to QtCreator, and Start Debugging again. When you get the SIGSEGV, look at your code in QtCreator: There will be a yellow arrow pointing to your error.

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          1 Reply Last reply
          0
          • A Offline
            A Offline
            A.J. Hwang
            wrote on last edited by
            #5

            I accidently SOLVED!!

            I programed delete searchResultPanel and re-new it right away.

            delete searchResultPanel;
            searchResultPanel = new QWidget(groupBox);
            verticalLayout_2->addWidget(searchResultPanel);
            

            But the problem was SIGNAL/SLOT!!

            I programed connect lineEdit's editFinished SIGNAL with refreshing the panel.

            Before doing your second advice I changed 'editFinished' SIGNAL to 'textChanged' and it works VERY WELL!!

            Anyway, thank you for your advices and have a good day ;)

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved