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 957175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:39:32+00:00 2026-05-16T00:39:32+00:00

I am writing an application in Qt to be deployed on Symbian S60 platform.

  • 0

I am writing an application in Qt to be deployed on Symbian S60 platform. Unfortunately, it needs to have Bluetooth functionality – nothing really advanced, just simple RFCOMM client socket and device discovery. To be exact, the application is expected to work on two platforms – Windows PC and aforementioned S60.

Of course, since Qt lacks Bluetooth support, it has to be coded in native API – Winsock2 on Windows and Symbian C++ on S60 – I’m coding a simple abstraction layer. And I have some problems with the discovery part on Symbian.

The discovery call in the abstraction layer should work synchronously – it blocks until the end of the discovery and returns all the devices as a QList. I don’t have the exact code right now, but I had something like that:

RHostResolver resolver;
TInquirySockAddr addr;
// OMITTED: resolver and addr initialization

TRequestStatus err;
TNameEntry entry;
resolver.GetByAddress(addr, entry, err);
while (true) {
    User::WaitForRequest(err);
    if (err == KErrHostResNoMoreResults) {
       break;
    } else if (err != KErrNone) {
        // OMITTED: error handling routine, not very important right now
    }

    // OMITTED: entry processing, adding to result QList

    resolver.Next(entry, err);
}
resolver.Close();

Yes, I know that User::WaitForRequest is evil, that coding Symbian-like, I should use active objects, and so on. But it’s just not what I need. I need a simple, synchronous way of doing device discovery.

And the code above does work. There’s one quirk, however – I’d like to have a timeout during the discovery. That is, I want the discovery to take no more than, say, 15 seconds – parametrized in a function call. I tried to do something like this:

RTimer timer;
TRequestStatus timerStatus;
timer.CreateLocal();

RHostResolver resolver;
TInquirySockAddr addr;
// OMITTED: resolver and addr initialization

TRequestStatus err;
TNameEntry entry;

timer.After(timerStatus, timeout*1000000);

resolver.GetByAddress(addr, entry, err);
while (true) {
    User::WaitForRequest(err, timerStatus);

    if (timerStatus != KRequestPending) { // timeout
        resolver.Cancel();
        User::WaitForRequest(err);
        break;
    }

    if (err == KErrHostResNoMoreResults) {
        timer.Cancel();
        User::WaitForRequest(timerStatus);
        break;
    } else if (err != KErrNone) {
        // OMITTED: error handling routine, not very important right now
    }

    // OMITTED: entry processing, adding to result QList

    resolver.Next(entry, err);
}
timer.Close();
resolver.Close();

And this code kinda works. Even more, the way it works is functionally correct – the timeout works, the devices discovered so far are returned, and if the discovery ends earlier, then it exits without waiting for the timer. The problem is – it leaves a stray thread in the program. That means, when I exit my app, its process is still loaded in background, doing nothing. And I’m not the type of programmer who would be satisfied with a “fix” like making the “exit” button kill the process instead of exiting gracefully. Leaving a stray thread seems a too serious resource leak.

Is there any way to solve this? I don’t mind rewriting everything from scratch, even using totally different APIs (as long as we’re talking about native Symbian APIs), I just want it to work. I’ve read a bit about active objects, but it doesn’t seem like what I need, since I just need this to work synchronously… In the case of bigger changes, I would appreciate more detailed explanations, since I’m new to Symbian C++, and I don’t really need to master it – this little Bluetooth module is probably everything I’ll need to write in it in foreseeable future.

Thanks in advance for any help! 🙂

  • 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-16T00:39:33+00:00Added an answer on May 16, 2026 at 12:39 am

    The code you have looks ok to me. You’ve missed the usual pitfall of not consuming all the requests that you’ve issued. Assuming that you also cancel the timer and do a User::WaitForRequest(timerStatus) inside you’re error handing condition, it should work.

    I’m guessing that what you’re worrying about is that there’s no way for your main thread to request that this thread exit. You can do this roughly as follows:

    • Pass a pointer to a TRequestStatus into the thread when it is created by your main thread. Call this exitStatus.
    • When you do the User::WaitForRequest, also wait on exitStatus.
    • The main thread will do a bluetoothThread.RequestComplete(exitStatus, KErrCancel) when it wants the subthread to exit, where bluetoothThread is the RThread object that the main thread created.
    • in the subthread, when exitStatus is signalled, exit the loop to terminate the thread. You need to make sure you cancel and consume the timer and bluetooth requests.
    • the main thread should do a bluetoothThread.Logon and wait for the signal to wait for the bluetooth thread to exit.

    There will likely be some more subtleties to deal correctly with all the error cases and so on.

    I hope I’m not barking up the wrong tree altogether here…

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

Sidebar

Related Questions

I'm writing a console application that will be deployed with an installation of an
I'm writing an application using Seam 2.2.x which will be deployed on JBoss 5.1.
We are writing a web application to be deployed on our intranet. We want
I am writing a web application to be deployed on tomcat . I am
I have a CakePHP based web application deployed on Apache (LAMP stack). Now I
I am writing a C# application to be deployed on another machine. The deploy
i have an asp.net web application and deployed on web server. in a scenario
I'm writing an ASP.Net Web Application that can be deployed to Web Farms. I've
I'm writing a WiX installer for an application which was deployed previously using ClickOnce.
I'm writing a Google AppEngine python application that needs to connect to Google for

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.