Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Threading don't creating buttons in frame
Forum Updated to NodeBB v4.3 + New Features

Threading don't creating buttons in frame

Scheduled Pinned Locked Moved Solved Qt for Python
11 Posts 4 Posters 1.2k 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.
  • eyllanescE Offline
    eyllanescE Offline
    eyllanesc
    wrote on last edited by eyllanesc
    #2

    @Black-Cat QObjects are not thread-safe, and even more so, QWidgets (which inherit from QObject) should not be created or modified in a thread other than the main thread. On the other hand I don't see any advantage of creating GUI in another thread. What are the benefits of using threads to create GUI elements?

    So: Is it possible to create buttons/items using a Threading? No, you can't and shouldn't.

    If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

    Black CatB 1 Reply Last reply
    1
    • eyllanescE eyllanesc

      @Black-Cat QObjects are not thread-safe, and even more so, QWidgets (which inherit from QObject) should not be created or modified in a thread other than the main thread. On the other hand I don't see any advantage of creating GUI in another thread. What are the benefits of using threads to create GUI elements?

      So: Is it possible to create buttons/items using a Threading? No, you can't and shouldn't.

      Black CatB Offline
      Black CatB Offline
      Black Cat
      wrote on last edited by
      #3

      @eyllanesc because in my original application I have a function that creation some buttons and when the function is turn on my app freezes by some second

      JonBJ eyllanescE 2 Replies Last reply
      0
      • Black CatB Black Cat

        @eyllanesc because in my original application I have a function that creation some buttons and when the function is turn on my app freezes by some second

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #4

        @Black-Cat
        Try not to use threads, and if you do they cannot create or do any UI stuff.

        If you really have to use them, emit a signal for the UI to create widgets if necessary.

        1 Reply Last reply
        1
        • Black CatB Black Cat

          @eyllanesc because in my original application I have a function that creation some buttons and when the function is turn on my app freezes by some second

          eyllanescE Offline
          eyllanescE Offline
          eyllanesc
          wrote on last edited by
          #5

          @Black-Cat Creating some elements of the GUI should not freeze the application so there are 2 options: 1) You are creating many buttons How many buttons are you creating? 2) There is another part of your application that is not creating buttons that is freezing the window.

          If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

          Black CatB 1 Reply Last reply
          0
          • eyllanescE eyllanesc

            @Black-Cat Creating some elements of the GUI should not freeze the application so there are 2 options: 1) You are creating many buttons How many buttons are you creating? 2) There is another part of your application that is not creating buttons that is freezing the window.

            Black CatB Offline
            Black CatB Offline
            Black Cat
            wrote on last edited by
            #6

            @eyllanesc

            only freeze in this process, basically:
            1 - connect in a socket
            2 - if socket response create a green button
            3 - if socket not response create a red button

            (have 1 socket)

            eyllanescE jsulmJ 2 Replies Last reply
            0
            • Black CatB Black Cat

              @eyllanesc

              only freeze in this process, basically:
              1 - connect in a socket
              2 - if socket response create a green button
              3 - if socket not response create a red button

              (have 1 socket)

              eyllanescE Offline
              eyllanescE Offline
              eyllanesc
              wrote on last edited by
              #7

              @Black-Cat So what is freezing the application is the sockets, not the creation of buttons. So you have the following options:

              • Execute the sockets in the secondary thread and use the signals to update the GUI in the main thread.
              • Use QTcpSocket (or similar class) since its methods are asynchronous.

              If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

              1 Reply Last reply
              0
              • Black CatB Black Cat

                @eyllanesc

                only freeze in this process, basically:
                1 - connect in a socket
                2 - if socket response create a green button
                3 - if socket not response create a red button

                (have 1 socket)

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

                @Black-Cat How do you connect using sockets? I hope you do not use any blocking API? Qt sockets are asynchronous, so nothing should block if you use them properly.

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

                Black CatB 1 Reply Last reply
                1
                • jsulmJ jsulm

                  @Black-Cat How do you connect using sockets? I hope you do not use any blocking API? Qt sockets are asynchronous, so nothing should block if you use them properly.

                  Black CatB Offline
                  Black CatB Offline
                  Black Cat
                  wrote on last edited by Black Cat
                  #9

                  @jsulm I don't using the QT socket, currently i'm using the socket of python... The freeze was because when a server socket is down it try much of 6 attemps to connect, and it freeze my software.

                  Btw I created the QTitens in normal mode and put the connections of socket in thread..... and don't freeze anymore

                  JonBJ eyllanescE 2 Replies Last reply
                  0
                  • Black CatB Black Cat

                    @jsulm I don't using the QT socket, currently i'm using the socket of python... The freeze was because when a server socket is down it try much of 6 attemps to connect, and it freeze my software.

                    Btw I created the QTitens in normal mode and put the connections of socket in thread..... and don't freeze anymore

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by JonB
                    #10

                    @Black-Cat
                    It sounds quite possible that the only reason you need threads is because you are choosing to use Python sockets (blocking?) in the first place! If that is the case, you should reconsider.

                    1 Reply Last reply
                    0
                    • Black CatB Black Cat

                      @jsulm I don't using the QT socket, currently i'm using the socket of python... The freeze was because when a server socket is down it try much of 6 attemps to connect, and it freeze my software.

                      Btw I created the QTitens in normal mode and put the connections of socket in thread..... and don't freeze anymore

                      eyllanescE Offline
                      eyllanescE Offline
                      eyllanesc
                      wrote on last edited by
                      #11

                      @Black-Cat See this example https://stackoverflow.com/questions/50413628/using-qlineedit-settext-freezes-the-window-but-background-tasks-works-fine/50415394#50415394

                      If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

                      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