Youtube API in Qt
-
Hello again :)
Anyone know how can I use the Youtube API and create a somewhat custom search in a widget? Something similar to the android youtube search... I do not want to add the whole page in a QWebView(that is easy) because I need the search to be rather small... Something like 300x300 px... Maybe scalable but the minimum width something like that.. I got the query results in a XML format but I don't know what to do from there on...
Thank you in advance.
Qt 4.8.4 (or 5.0)
Windows 7 -
Use the youtube API's https://developers.google.com/youtube/getting_started#data_api
You will need to write your own Qt-wrapper for these but should not be particularly difficult. Qt provides all the building blocks that you need.
-
thank you. my problem wasn't with the youtube api... it was with writting the wrapper though :)
-
Ah, sorry I misunderstood. QNetworkAccessManager is your friend in this case. Wrap this up in your own class and add member functions that map onto requests using the youtube API.
Or do you have a more specific problem with doing this type of thing?
-
The problem i'm having is constructing a custom widget in which to display the results of the query I get from youtube API. it's more of a XML problem now that I think of it... Not so much in the API. I'm not certain on how to reconstruct parts of the XML in my custom widget :) I think I should use the QDeclarativeView class (not certain) to add the XML. Am I even close to the solution? :D
-
OK I see what you are getting at now. What I would suggest is something along these lines:
Construct a class that issues the API calls to youtube
When the data is returned to you process the XML (I assume it is xml from what you said) using QXmlStreamReader.
Create a class that inherits from QAbstractListModel. Populate this list with items from contained in your xml (i.e. search results).
If you are using QML (which sounds like it will be a good fit in this case), create a QML document that contains a ListView element along with a custom delegate element (this gets created for each item in your list model).
From C++ expose your list model of results to QML using QDeclarativeContext::setContextProperty()
In QML set the "model" property of your list to the id of your exported model.
That is the basic setup. Of course you can go further by having a TextInput QML element to control what to search for on youtube etc.
Take a look at some of the QML examples with custom C++ list models that ships with Qt.
Please feel free to come back with specific questions on the above steps.