Nominate our 2022 Qt Champions!

One QNetworkAccessManager instance.

  • Looking at the QNetworkAccessManager doc ,It suggests that just having one instance in the entire Qt application is enough.Can anyone enlighten me on the reason why? I usually have one instance in my applications and it become a habit.I had a discussion with one of my teammates (whos been instantiating tones of them in his applications) and besides it makes your app more manageable and the official Qt doc suggests it ,I couldn't come up with a compeling reason.Do you guys know of other reasons the Doc suggests one instance?Thank you for your time.

  • QNetworkAccessManager doesn't actually do much in the way of actually handling network connections. Once it creates a QNetworkReply object - for example as a result of the application calling the get() or post() method - its job is pretty much done. The actual work of reading/writing data to/from the socket will be handled by the QNetworkReply object itself. Since you can create as many of these objects as you want using a single QNetworkAccessManager there really is no need to have more than one network access manager object alive at any given time.

Log in to reply