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

  • SEARCH
  • Home
  • 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 6760523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:04:27+00:00 2026-05-26T14:04:27+00:00

I’ve written some library code (in C) to facilitate creating and querying threads independent

  • 0

I’ve written some library code (in C) to facilitate creating and querying threads independent of the platform. Here’s a psuedo-code example of the API to create a thread:

 result OS_createThread ( 
      pointer to thread handle (set after thread is created), 
      stack size,
      function to run, 
      pointer to parameters,
      priority )

Depending on the platform, I use the appropriate c file that contains the particular OS implementation to kick off the thread. E.g.

result OS_createThread ( 
 // Windows implementation
 map priority to Windows priority
 // Use Win32 threading call
 CreateThread(blah blah)

I’ve created ports for Win32, POSIX threads, and some RTOSes I’ve used. Now I need to do this for a Qt environment and I’m a little stumped. First off, I’m a Qt newbie, second it looks like it will require an object oriented approach using the QThread class.

The point of this is to hide the guts of the thread creation to the caller. The caller wants to be able to kick off threads and maintain a handle to that thread so that it can do things in the future like change its priority or kill it.

Using QThreads, does a new QThread object need to be created each time a new thread is requested? Keep in mind that the calling code cannot have anything Qt-specific.

Any guidance is appreciated!

  • 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-26T14:04:27+00:00Added an answer on May 26, 2026 at 2:04 pm

    To create a QThread you would implement a class inheriting from QThread. Example taken from the QT Documentation

    class MyThread : public QThread
     {
     public:
         void run();
     };
    
     void MyThread::run()
     {
         QTcpSocket socket;
         // connect QTcpSocket's signals somewhere meaningful
         ...
         socket.connectToHost(hostName, portNumber);
         exec();
     }
    

    And hidden in your implementation would be:

    result OS_createThread ( 
          pointer to thread handle (set after thread is created), 
          stack size,
          function to run, 
          pointer to parameters,
          priority )
    {
      MyThread *thread = new MyThread(size, function, parameters, prio);
      thread->start();
      return thread;
    }
    

    So your C interface method would create an instance of such a class for each thread being requested. This class should then store all the relevant data passed from your function within its member variables. The thread function to be executed would be called within the run() method. Since you seem to execute only C methods I see no problem storing a pointer to them within a class variable (please correct me anyone if I’m wrong – haven’t tried it yet ;).

    However, its actually a bit more tricky than that, because somebody will have to free the memory created for the thread variable. And thats not easily (from a C interface) possible with my example. So you might want to think about using an internal manager class or something that handles the created threads and destroys them as needed. In order to make a qualified statement about how you could achieve this, however, I’d need a bit more information 😉

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm making a simple page using Google Maps API 3. My first. One marker
I have some data like this: 1 2 3 4 5 9 2 6
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
i got an object with contents of html markup in it, for example: string
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

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.