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. Run Server code in different QThread
QtWS25 Last Chance

Run Server code in different QThread

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 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.
  • N Offline
    N Offline
    nnicou
    wrote on last edited by
    #1

    Hello, i have been struggling for a solution the past days. I want to create a new Qthread as a server(c++) in it and base on the data update the GUI in qml.
    First of all i decided to go with QT Quick Controls 2 Application.
    As i read i need to re implement ::run() function in my Thread class(use server code there).
    My problem is how to emit signals base on c++ code changes, i did tried some examples but nothing gets to work.
    It would be helpful if someone could advice me how to start,is the feasible?

    General Question: Is the correct way to update QML through main.cpp? so new QThread communicate with main.cpp and main.cpp will update QML?

    raven-worxR 1 Reply Last reply
    0
    • N nnicou

      Hello, i have been struggling for a solution the past days. I want to create a new Qthread as a server(c++) in it and base on the data update the GUI in qml.
      First of all i decided to go with QT Quick Controls 2 Application.
      As i read i need to re implement ::run() function in my Thread class(use server code there).
      My problem is how to emit signals base on c++ code changes, i did tried some examples but nothing gets to work.
      It would be helpful if someone could advice me how to start,is the feasible?

      General Question: Is the correct way to update QML through main.cpp? so new QThread communicate with main.cpp and main.cpp will update QML?

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @nnicou said in Run Server code in different QThread:

      General Question: Is the correct way to update QML through main.cpp? so new QThread communicate with main.cpp and main.cpp will update QML?

      that wont work. Since your main.cpp should start the event-loop.
      You need to update the GUI/QML from inside the event loop.

      For example one possibility could be to create a global context object and connect it to the thread, In QML you then can connect to this contect object and update the parts you need to.

      But probably it's the best to show some code.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • N Offline
        N Offline
        nnicou
        wrote on last edited by
        #3

        I dont have anything that works yet.I only have plain c++ knowledge and i am currently asking in which direction i should go and sorry for my silly questions
        Well i am still wondering if is better to use Widgets instead of QML
        C++ Logic will collect data from a Multi-core simulator through sockets and save ,lets say in a vector cycle by cycle the data in a class/sructure. (I want the Gui to be interactive and get info per Router etc)

        Question:Can i build my whole Graphical enviroment from C++ (MainWindow)and the second thread update that file? (Like FortuneServer Example)
        Which is the better approach QT quick or Widgets?

        raven-worxR 1 Reply Last reply
        0
        • N nnicou

          I dont have anything that works yet.I only have plain c++ knowledge and i am currently asking in which direction i should go and sorry for my silly questions
          Well i am still wondering if is better to use Widgets instead of QML
          C++ Logic will collect data from a Multi-core simulator through sockets and save ,lets say in a vector cycle by cycle the data in a class/sructure. (I want the Gui to be interactive and get info per Router etc)

          Question:Can i build my whole Graphical enviroment from C++ (MainWindow)and the second thread update that file? (Like FortuneServer Example)
          Which is the better approach QT quick or Widgets?

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @nnicou said in Run Server code in different QThread:

          Which is the better approach QT quick or Widgets?

          depends what you are planning to do. If you just want a Desktop app, i think it's easier for now to stay with QtWidgets and C++ only.

          Only important thing about the thread communication is you can use signals/slots and make sure you connect to the signals using Qt::QueuedConnection in the connect() statement.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          1
          • N Offline
            N Offline
            nnicou
            wrote on last edited by
            #5

            Yeah i just want a Desktop app i will search about QueuedConnection thank you for the hint!

            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