On Tue, May 4, 2010 at 7:00 AM, Martin Jones <[email protected]> wrote:

> On Thu, 29 Apr 2010 11:11:42 pm ext Jack Wootton wrote:
> > Hi,
> >
> > It is now working.  It seemed to be a combination of problems:
> >
> > 1. There was a problem with the proxy I was using which has now been
> fixed.
> >
> > 2. When the proxy contained "http://"; it did not work.  Instead I
> changed
> > it back to just "my.proxy.com<http://my.proxy.com>" and set
> QNetworkProxy
> > type to HttpProxy.
> >
> > My final code for the create method looked like this:
> >
> > QNetworkProxy proxy;
> > proxy.setHostName("my.proxy.com<http://my.proxy.com>");
> > proxy.setPort(3128);
> > proxy.setType(QNetworkProxy::HttpProxy);
>
> I'm surprised that works.  I would have thought that the proxy host should
> be
> "my.proxy.com" without the URL in the angle brackets.
>

Some formatting has taken place along the way, I don't use any angle
brackets. i use a single proxy address which excludes http://


> > I still have one unanswered question from before :)
> >
> > I removed a call to the static method
> >
> > QNetworkProxy::setApplicationProxy(proxy);
> >
> > ... because of the need for create(QObject* parent) to be re-entrant.
> > Is it OK to call this static method from a re-entrant method?  If so,
> > should the documentation make this clear?
>
> That method appears to be protected by a mutex, so it should be safe.  You
> can
> file a bug at http://bugreports.qt.nokia.com if the documentation is
> insufficient


Thank you


> .
>
> Martin.
>
>
> > Thank you for your help too :)
> >
> > On Thu, Apr 29, 2010 at 7:01 AM, Martin Jones
> > <[email protected]<mailto:[email protected]>> wrote:
> >
> > On Wed, 28 Apr 2010 11:12:11 pm ext Jack Wootton wrote:
> > > To follow up on this.  I have been reading the documentation for
> > > QNetworkProxyFactory:
> > > http://doc.qt.nokia.com/4.7-snapshot/qnetworkproxyfactory.html
> > >
> > > For the method
> > >
> > > QList<QNetworkProxy> QNetworkProxyFactory::systemProxyForQuery ( const
> > > QNetworkProxyQuery & query = QNetworkProxyQuery() )   [static]
> > >
> > > it is documented that: "On Windows, this function will use the WinHTTP
> > > DLL functions. Despite its name, Microsoft suggests using it for all
> > > applications that require network connections, not just HTTP. This will
> > > respect the proxy settings set on the registry with the proxycfg.exe
> > > tool. If those settings are not found, this function will attempt to
> > > obtain Internet Explorer's settings and use them."
> > >
> > > I'm have set my proxy using proxycfg tool on Windows, however I still
> get
> > > no proxy results from QNetworkProxyFactory::systemProxyForQuery
> >
> > QNetworkProxyFactory::systemProxyForQuery() requires a QNetworkProxyQuery
> > to be passed to it.  This would also require using a
> QNetworkProxyFactory,
> > rather than simply setting a proxy for the QNetworkAccessManager.  If you
> > want to do this then you can see the qml runtime source for inspiration -
> > tools/qml/qmlruntime.cpp (search for SystemProxyFactory).
> >
> > To begin, I think you should get the code below working, though.  I
> suspect
> > the reason it does not work is that you have not provided a valid host
> > name:
> >
> >
> > proxy.setHostName("my.proxy.com<http://my.proxy.com><http://my.proxy.com
> >"
> > );
> >
> > changing it to this should make it work:
> >
> >     proxy.setHostName("my.proxy.com<http://my.proxy.com>");
> >
> > assuming my.proxy.com<http://my.proxy.com> is a valid proxy.
> >
> > I've added a simple example to examples/declarative/proxyviewer,
> > illustrating how to use a QDeclarativeNetworkAccessManagerFactory (should
> > appear on gitorious within 24hrs).  The code is essentially the same as
> > you have below, so with a correct proxy set this should work.
> >
> > Martin.
> >
> > > On Tue, Apr 27, 2010 at 2:35 PM, Jack Wootton
> > > <[email protected]<mailto:[email protected]><mailto:
> jackwoot...@g
> > > mail.com<mailto:[email protected]>>> wrote: Hello,
> > >
> > > I have modifed the my implementation of
> > > QDeclarativeNetworkAccessManagerFactory (question follows code) :)
> > >
> > > MyNetworkAccessManagerFactory.h
> > > ===========================
> > > class MyNetworkAccessManagerFactory : public
> > > QDeclarativeNetworkAccessManagerFactory {
> > >
> > > public:
> > >      MyNetworkAccessManagerFactory();
> > >      ~MyNetworkAccessManagerFactory();
> > >
> > > public:
> > >     QNetworkAccessManager* create ( QObject * parent );
> > >
> > > };
> > >
> > >
> > > MyNetworkAccessManagerFactory.cpp
> > > =============================
> > > MyNetworkAccessManagerFactory::MyNetworkAccessManagerFactory()
> > > {
> > > }
> > >
> > > MyNetworkAccessManagerFactory::~MyNetworkAccessManagerFactory()
> > >
> > > {
> > > }
> > >
> > > QNetworkAccessManager* MyNetworkAccessManagerFactory::create ( QObject*
> > > parent ) {
> > >
> > >      QNetworkProxy proxy;
> > >      proxy.setHostName("my.proxy.com<http://my.proxy.com><
> http://my.proxy
> > >      .com>");
> > >
> > >      proxy.setPort(3128);
> > >
> > >      // Is this static method call acceptable for a re-entrant method?
> > >      // QNetworkProxy::setApplicationProxy(proxy);
> > >
> > >      QNetworkAccessManager* nam = new QNetworkAccessManager(parent);
> > >
> > >
> > >      nam->setProxy(proxy);
> > >      return nam;
> > >
> > > }
> > >
> > >
> > >
> > > I have a question about ensuring the method create(QObject* parent) is
> > > thread safe / re-entrant: I assumed the method call
> > > 'QNetworkProxy::setApplicationProxy(proxy);' is not ok since it is
> static
> > > and should not be called from a re-entrant function.  Is this the case?
> > > If so, is it a problem that it is not called?
> > >
> > > I made the changes, but I still don't see the webpage loaded in the QML
> > > document, but I'll deal with that after I know my code is correct first
> > > :)
> > >
> > >
> > >
> > > On Tue, Apr 27, 2010 at 2:19 AM, Martin Jones
> > > <[email protected]<mailto:[email protected]><mailto:
> martin.jone
> > > [email protected]<mailto:[email protected]>>> wrote:
> > >
> > > On Tue, 27 Apr 2010 01:18:56 am ext Jack Wootton wrote:
> > > > Hi,
> > > >
> > > > I'm trying to set some proxy settings for a QML application - it's
> not
> > > > working as expected.  I'm unsure the API is being used correctly, can
> > > > someone check my code makes sense? There are 3 files: main.cpp,
> > > > MyNetworkAccessManagerFactory.h and MyNetworkAccessManagerFactory.cpp
> > > >
> > > > I'm using qt 4.7 and followed the documentation
> > > > (
> http://doc.qt.nokia.com/4.7-snapshot/qdeclarativenetworkaccessmanagerf
> > > > ac t ory.html) when writing the code.  The method
> > > > MyNetworkAccessManagerFactory::create(QObject* parent) does get
> called
> > > > when the QML document is loaded using the QDeclarativeView, so the
> > > > framework is definitely picking up the new proxy settings.
> > > >
> > > > The questions I have are:
> > > >
> > > > 1. Is the implementation of MyNetworkAccessManagerFactory::create
> > > > correct? I assumed because I was subclassing from a class with
> > > > 'factory' in its name, that it was ok to return the same pointer to
> > > > NetworkAccessManager.
> > > >
> > > > 2. How do I know if the method that calls "create" takes ownership of
> > > > the returned pointer or not?  I assumed it didn't, hence cleaning up
> > > > in ~MyNetworkAccessManagerFactory();
> > > >
> > > > 3. Is there anything obviously wrong with the way I'm using the
> > > > NetworkAccessManager?
> > >
> > > The factory must create a  new NAM each time it is called.  This is
> > > because QML creates multiple threads and each must have its own NAM.
>  It
> > > is important that you set the parent of the NAM created to the parent
> > > passed in the create() method (which you already do).  The NAM will be
> > > destroyed when its parent is destroyed.  I will update the
> documentation
> > > to make this clear.
> > >
> > > Also take special note of this line from the documentation:
> > >
> > > "Note: the create() method may be called by multiple threads, so ensure
> > > the implementation of this method is reentrant."
> > >
> > > --
> > > Martin
> > >
> > >
> > >
> > > --
> > > Regards
> > > Jack
> > >
> > >
> > >
> > > --
> > > Regards
> > > Jack
> >
> > --
> > Martin
> >
> >
> >
> > --
> > Regards
> > Jack
>
> --
> Martin
>



-- 
Regards
Jack
_______________________________________________
Qt-qml mailing list
[email protected]
http://lists.trolltech.com/mailman/listinfo/qt-qml

Reply via email to