Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Posts: 17,025
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Processing queue in Qt?

Is there an existing solution in Qt i could use for a background queue?

 

In (bb) java i throw runnables into a vector and have a threadpool that sleeps until something is in the queue.

 

My target would be to have the ability to queue networking requests (wrapped into some kind of runnable) when the device is out of coverage and trigger them when coverage comes back.

 

Before i go and implement it myself i wanted to inquire if there are some special Qt  things (or c++ libs) i could use as i don't have a broad overview of these capabilities at the moment.

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Regular Contributor
Posts: 51
Registered: ‎06-29-2011
My Device: Z10 Limited Edition
My Carrier: Ukraine GSM

Re: Processing queue in Qt?

As I understand you had a separate thread for each request and stored those threads in a threadpool? If you want to go that way, you can use QThread and QThreadPool, but I don't recommend that.

 

In Qt, you can be fine with just one thread, if you use signals and slots. My suggestion would be just to store requests somewhere (for example in QVector) and when you have coverage, send them out, something like this:

void MyWindow::onCoverageComesBack()
{
  for (int i = 0; i < this->requests.size(); ++i)
  {
    this->networkAccessManager.post(this->requests[i]);
  }
}

 You can also have a look at QNetworkAccessmanager class to determine if connection is available

Developer
Posts: 17,025
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Processing queue in Qt?

I am currently thinking about a runnable class extending both QObject (to have signals) and QRunnable and just using the global threadpool.
I won't have that many processes queued, maybe up to a few dozen.

The signal would be used to track the success of the request in the queue.

What i would need is a signal that indicates that the network is accessible, currently i know only of https://developer.blackberry.com/cascades/reference/qnetworkaccessmanager.html#networkAccessible-pro...
which i would have to query repeatedly.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Regular Contributor
Posts: 51
Registered: ‎06-29-2011
My Device: Z10 Limited Edition
My Carrier: Ukraine GSM

Re: Processing queue in Qt?

You don't need to query it over and over again. Just subscribe to change signal:

connect(m_networkAccessManager,
            SIGNAL(networkAccessibleChanged(QNetworkAccessManager::NetworkAccessibility),
            this, 
            SLOT(onNetworkAccessibilityChanged(QNetworkAccessManager::NetworkAccessibility));

 Get familiar with Qt signals and slots, they are really meant to be used everywhere in Qt

Developer
Posts: 17,025
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Processing queue in Qt?

I am familiar with them, i just seem to have tired eyes and did not see the signal. Thanks Smiley Happy
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter