08-15-2014 09:57 PM
I am in desperate need of help right now. I recently changed my app to use OAuth2, but it gives me an access token that i need to refresh every hour. The problem is that when my app starts, I need to make the API http call to refresh the token BEFORE any other API calls occur. I have tried so many different ways of doing this, but I can't get it quite right.
I tried using QEventLoop which is what I found online to be a way of making QNetworkManager request synchronous (since by nature it is asynchronous). First I tried doing this before creating the QML file...
QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(th
But then when I quit the QEventLoop, it wouldn't continue on with the rest of the code, I guess because the main event loop begins right after this line to creat the QML is called ^. So by entering a separate QEventThread before the main event thread has started, i can't seem to get back.
So then I tried doing it right after creating the QML file via that line above. However, this also doesn't seem to work well because sometimes if the QNetworkReply takes a long time to come back, the QML files have already intiialized and started other API calls to retrieve data, without having a valid token to send so they all come back as failed http requests.
Does anybody know a good way of going about this? I need to make this Http request to refresh my authentication token BEFORE anything else happens, especially before any other API calls happen since otherwise they won't be valid..
Solved! Go to Solution.
08-16-2014 07:26 AM
easiest way would be before making any api calls to check the token if it's valid or must be refreshed
08-16-2014 11:25 AM
08-16-2014 11:36 AM
aaah - understand
then at first you should change your Tabs and only do a lazy loading if they'll be touched the first time
this will make sure the qml content won't be loaded before first TAP on the TAb
and from your first Tab you should check if you alreay got the token -
if not do your stuff to get the token while displaying a progress dialog or so
then when you get the token do the first api call
08-16-2014 01:15 PM
I did try using the Delegate class to load tabs as they are needed, but I ran into issues because at the root of each tab I have a NavigationPane. The delegate property asks for a source qml file which needs to have a Page element at its root. I could'nt figure out a way to maintain my navigationpanes while using the Delegate class to dynamically load my tabs. Do you know any way around this?
08-17-2014 02:13 AM
I did try using the Delegate class to load tabs as they are needed, but I ran into issues because at the root of each tab I have a NavigationPane. ....
I'm doing the same without an issue. See here my Navigation Concept using TabbedPane as root and NavigationPanes on top of the Tabs:
.... The delegate property asks for a source qml file which needs to have a Page element at its root. I could'nt figure out a way to maintain my navigationpanes while using the Delegate class to dynamically load my tabs. Do you know any way around this?
You can do it using Delegates - see here some code. (scroll down to 'create dynamic and destroy')