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. Refresh tableView when new row inserted in DB
Forum Update on Monday, May 27th 2025

Refresh tableView when new row inserted in DB

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 1.1k Views
  • 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.
  • ZoptuneZ Offline
    ZoptuneZ Offline
    Zoptune
    wrote on last edited by
    #1

    Hi,

    I have a tableview that display the result of a sql query and i want to refresh that view when a new row is inserted in the sql table.
    How can i do ?

    • refresh every n minutes (not sexy)

    • triggered event in DB emits a signal (SqlDriver subscribed DB notification)
      The problem with this solution is that, to receive signal, the DB need to be open() all the time (not good i think).

    Wich way is the best ?
    Any better solution ?

    Thanks

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      personally I'd give the DB a name in your app and leave it open.
      As an alternative you can run a QTcpServer/QLocalServer on your application, build a small utility that connects to it and sends the infos of what was updated and shell the utility from a stored procedure

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      1
      • ZoptuneZ Offline
        ZoptuneZ Offline
        Zoptune
        wrote on last edited by
        #3

        Isn't it bad to let the app and the db connected all the time ?
        I thought that the right way to use a db was to connect just before the query and close just after.
        Am i wrong ?

        1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by VRonin
          #4

          In general terms yes but it depends on how busy the DB is. if your application will always be the only DB connection leaving it open is totally fine.
          The problem comes from how many connections your database allows: MS SQL Server allows 32767 connections at any given time, SQLite (this is a guess) just 1.

          If you are confident you will never run out of connections leave the DB open, otherwise use the TCP method

          Edit:
          Thinking about how it should work you'll probably need 2 utility apps:
          1 server always running on a known location (the database server machine?) that your main app will connect to
          1 client shelled from the stored procedure that sends the info to the server, the server bounces the infos to the main app

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          0
          • ZoptuneZ Offline
            ZoptuneZ Offline
            Zoptune
            wrote on last edited by
            #5

            Ok, i think i'll leave the DB open all the time.

            Thank you

            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