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. Can't update Grid Layout
Forum Updated to NodeBB v4.3 + New Features

Can't update Grid Layout

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 345 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.
  • Ramkumar MohanR Offline
    Ramkumar MohanR Offline
    Ramkumar Mohan
    wrote on last edited by
    #1

    If I add data in sqlite db, it will be added in grid layout, but if I delete data from db, it will be deleted in grid layout, it will not update, the deleted data will show in grid layout, if I close the program and then open it, it will update. How to programmatically update the grid layout in QT.

    OS : Linux
    DB : Sqlite

    jsulmJ 1 Reply Last reply
    0
    • Ramkumar MohanR Ramkumar Mohan

      If I add data in sqlite db, it will be added in grid layout, but if I delete data from db, it will be deleted in grid layout, it will not update, the deleted data will show in grid layout, if I close the program and then open it, it will update. How to programmatically update the grid layout in QT.

      OS : Linux
      DB : Sqlite

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Ramkumar-Mohan said in Can't update Grid Layout:

      How to programmatically update the grid layout in QT.

      You did not post your code nor did you explain how you're deleting entries from grid layout! How should anybody help you?
      If you want to show data from database why don't you use https://doc.qt.io/qt-6/qtableview.html instead?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      Ramkumar MohanR 1 Reply Last reply
      1
      • jsulmJ jsulm

        @Ramkumar-Mohan said in Can't update Grid Layout:

        How to programmatically update the grid layout in QT.

        You did not post your code nor did you explain how you're deleting entries from grid layout! How should anybody help you?
        If you want to show data from database why don't you use https://doc.qt.io/qt-6/qtableview.html instead?

        Ramkumar MohanR Offline
        Ramkumar MohanR Offline
        Ramkumar Mohan
        wrote on last edited by
        #3

        @jsulm

        QSqlQuery query;
        query.prepare("SELECT name FROM test");
        query.exec();
        int count=0;
        while(query.next())
        {
            QString s=query.value(0).toString();
            array[count]=s;
            count++;
            //qDebug()<<s;
        }
        int count1=0;
        const QSize btnSize = QSize(150, 50);
        for (int i=0;i<15 ;i++ )
        {
            for (int j=0;j<5 ;j++ )
            {
                if(count1==count)
                    break;
                else
                {
                    QPushButton *button = new QPushButton(array[count1]);
                    button->setFixedSize(btnSize);
                    button->setObjectName(array[count1]);
                    connect(button, &QPushButton::clicked, this,&MainWindow::cald);
                    ui->gridLayout->addWidget(button,i,j);
                    count1++;
                }
            }
        }
        

        pic.jpg

        According to the above code some buttons are add their name in grid layout and functions are store in db and save in table named test, and if a data delete in db is not remove widget in grid layout. how to remove the deleted data widget.

        Delete function :

        QString Name = "name15";
        QSqlQuery query;
        query.prepare("Delete from test where name='"+Name+"'");
        if(query.exec())
        {
            qDebug()<<"Data Deleted";
           ui->gridlayout->update();
        }
        
        jsulmJ 1 Reply Last reply
        0
        • Ramkumar MohanR Ramkumar Mohan

          @jsulm

          QSqlQuery query;
          query.prepare("SELECT name FROM test");
          query.exec();
          int count=0;
          while(query.next())
          {
              QString s=query.value(0).toString();
              array[count]=s;
              count++;
              //qDebug()<<s;
          }
          int count1=0;
          const QSize btnSize = QSize(150, 50);
          for (int i=0;i<15 ;i++ )
          {
              for (int j=0;j<5 ;j++ )
              {
                  if(count1==count)
                      break;
                  else
                  {
                      QPushButton *button = new QPushButton(array[count1]);
                      button->setFixedSize(btnSize);
                      button->setObjectName(array[count1]);
                      connect(button, &QPushButton::clicked, this,&MainWindow::cald);
                      ui->gridLayout->addWidget(button,i,j);
                      count1++;
                  }
              }
          }
          

          pic.jpg

          According to the above code some buttons are add their name in grid layout and functions are store in db and save in table named test, and if a data delete in db is not remove widget in grid layout. how to remove the deleted data widget.

          Delete function :

          QString Name = "name15";
          QSqlQuery query;
          query.prepare("Delete from test where name='"+Name+"'");
          if(query.exec())
          {
              qDebug()<<"Data Deleted";
             ui->gridlayout->update();
          }
          
          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Ramkumar-Mohan said in Can't update Grid Layout:

          how to remove the deleted data widget

          Using https://doc.qt.io/qt-6/qgridlayout.html#takeAt for example.
          Or https://doc.qt.io/qt-6/qlayout.html#removeWidget

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          2

          • Login

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