Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use QNetworkAccessManager in different classes? General sharing of important data between classes?
    primarykey
    data
    text
    <p>I have a MainWindow application I'm working on to learn C++ and Qt (C++ and QT 4.8). I want to do HTTP requests in different objects of my application, such as Dialogs/Wizard and in the MainWindow. I know I'm basically supposed to have one QNetworkAccessManager per application. My question is, what is the proper way to pass this QNAM around between classes? </p> <p>At the moment I have it as a pointer I pass to the constructor of my wizard but this seems... inelegant and inflexible. What is the proper way to give my Dialogs or whatever other classes I decide to make, access to my one QNetworkAccessManager? I guess I have the same question about any piece of data I need to give everything access to. </p> <p>What is the properly C++-designed solution here? The singleton pattern seems like an option, but a bad one as I understand. I have a bit of code here to show my question.</p> <p>My MainWindow constructor and slot which launch my wizard:</p> <pre><code>MyMainWindow::MyMainWindow { qnam = new QNetworkAccessManager(); } ... MyMainWindow::wizardStarter { mywizard = MyWizard(vari, qnam, this); } </code></pre> <p>My Wizard Constructor in which I'm making network requests and parsing data after getting data from the user, and therefore in which I need a QNetworkAccessManager:</p> <pre><code>MyWizard::MyWizard(SomeOtherArgument *vari, QNetworkAccessManager *qnam, QObject *parent) { ... this-&gt;ourQnam = qnam; ... } MyWizard::launchRequest(QUrl newUrl) { ourQnam-&gt;get(QNetworkRequest(newUrl)); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload