Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 629805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:47:14+00:00 2026-05-13T19:47:14+00:00

I have a qthread that uses a udp socket to write and read datagrams

  • 0

I have a qthread that uses a udp socket to write and read datagrams in a loop. the QUDPSocket is created in the mainthread. How do I handle QObjects that I will use in both the QThread and mainthread. Also is it ok to have the UDP socket in the mainthread and use it in the qthread?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T19:47:14+00:00Added an answer on May 13, 2026 at 7:47 pm

    Typically you should only allow one thread to deal with each QObject. In this case, you would probably want to have your QThread hold and use the QUDPSocket, and the main thread would not ever touch it (ideally the main thread shouldn’t even be holding a pointer to the QUDPSocket, just to be sure you never forget and accidentally call a method on it from the wrong thread).

    When your QThread reads some UDP data, it can do any initial processing on it, then pass the data to the main thread via QApplication::postEvent() or via a queued signal/slot connection.

    Similarly, if your main thread has some data that it would like to be sent out as a UDP packet, it shouldn’t call write() on the QUDPSocket object directly; instead it should notify the QThread (via postEvent() or a queued signal) and let the QThread handle it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a QThread that contains a QUDPsocket (socket is member not local to
I have a QThread that reads from a socket and sends a signal (QT
I have a QThread derived class that communicates with the main thread by sending
I have an object that is derived from QThread and the class definition includes
I have a worker QThread in which a QObject derived object is created. The
i have a QMainWindow that starts a QThread and waits for data from the
I read on internet that subclassing (that deriving a class from Qthread) and then
I am currently trying implement a QThread that contains a socket connection. The socket
I have a class like this class GUI : public QWidget, public QThread When
have 2 questions : A computer with 32-bit address uses 2-level page table (9

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.