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. SOLVED: create Libary wich is used by multiple qt programms, that has one instance

SOLVED: create Libary wich is used by multiple qt programms, that has one instance

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 Posters 2.3k 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.
  • M Offline
    M Offline
    M001
    wrote on 13 Aug 2013, 14:43 last edited by
    #1

    hey,
    I wrote a Class that connects to an SQL Databes and reads and writes information. I built this Class into a dll Libary. Now here's the question: If I use this .dll in multiple qt applications, does this create a new instance of my class on every usage of the dll, or is there just one instance of my class, which is used by all qt applications.
    Tanks for your help

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 13 Aug 2013, 15:13 last edited by
      #2

      Hi,

      It will create a new instance each time an application uses it

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • M Offline
        M Offline
        M001
        wrote on 13 Aug 2013, 15:17 last edited by
        #3

        How can i Force them to use all the Same imstance? Or make a class property, which is Used by all instances?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 13 Aug 2013, 19:21 last edited by
          #4

          You can't, if you need to access some common data you either have to store them somewhere in memory or in a database etc...

          But several applications can't share one instance of an object

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • M Offline
            M Offline
            MuldeR
            wrote on 13 Aug 2013, 19:32 last edited by
            #5

            Yes, each application (more specifically: process) that loads the DLL gets its own instance. That at least applies to the writable "data" section, which is never shared. The read-only "text" (i.e. program code) section may actually be shared to save physical memory, but that won't help to exchange data between instances. In reality, though, Windows will rarely share DLL "text" sections between processes, due to re-allocation - which requires each process to have its own separate copy of the program code.

            BUT: If you want to exchange data between all processes using your DLL, your DLL can internally use a QSharedMemory. Probably in conjunction with QSystemSemaphore instances to avoid race conditions when accessing the shared memory area. This works very nice for me to realize IPC.

            My OpenSource software at: http://muldersoft.com/

            Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

            Go visit the coop: http://youtu.be/Jay...

            1 Reply Last reply
            0
            • M Offline
              M Offline
              M001
              wrote on 13 Aug 2013, 19:53 last edited by
              #6

              Thanks for your answers. Okay so i cant have One instance of my class between more processes. Then the singelton Pattern wont work too?
              Maybe there is another Solution for my problem. Basicly i want to exess an SQL Database via different processes and i want to use a class which Handels the Access to the Database. So i tryed to Write a dll with a class in it that conects to the Database and gives Access to it via different slots. There should be only one instance of this class, so that i dont have to use multiple connections to the Database from all the instances. I Hope you get an Idea of what i am Planing to Build :). If you have any better solutions for my Problem please Tell them to me.

              1 Reply Last reply
              0
              • M Offline
                M Offline
                MuldeR
                wrote on 13 Aug 2013, 20:00 last edited by
                #7

                Well, you could create some kind of "middle-ware" application that handles all the SQL DB access, running as a special process. The other "client" processes could then communicate with the "middle-ware" process via QSharedMemory and QSystemMutex. The logic that is required for a "client" process to send requests to the "middle-ware" process (and to retrieve the result) could be wrapped into a DLL, for easy re-use in multiple (client) applications.

                My OpenSource software at: http://muldersoft.com/

                Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

                Go visit the coop: http://youtu.be/Jay...

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  M001
                  wrote on 13 Aug 2013, 20:07 last edited by
                  #8

                  Thanks for the fast answer :). Sounds Good, do you have an exampelcode or is there a Tutorial wich describes this Kind of Solution?

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    MuldeR
                    wrote on 13 Aug 2013, 20:19 last edited by
                    #9

                    I have implemented IPC like this:
                    http://pastie.org/private/oj0mgxa4sktawadqqhptg

                    My OpenSource software at: http://muldersoft.com/

                    Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

                    Go visit the coop: http://youtu.be/Jay...

                    1 Reply Last reply
                    0

                    1/9

                    13 Aug 2013, 14:43

                    • Login

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