I am using a delegate to show a standard item model data into a listview in qt.
The model has a QIcon and a header and subheader strings.
Now i want to load remote images via http into the listview asynchronously.
How can i do this?
I have already got the listview running.
There are a lot of different ways to solve your task, and correct answer depends on how you're building your ui and what it's meant for and how other components in your application work. Nevertheless, here's an idea for you to consider:
Create a model for your listview, a guess each item of your model should have a link to the icon\image which you're going to download.
Use QNetworkAccessManager to connect to asynchronously download the image via http. Example of you can do this is here: qt networkManager get
Once an image is downloaded network manager's "finished" signal handler will be called, there you need to update a record in your model corresponding to the downloaded link with the pointer to the image object.
For the list you can use an item delegate to draw an empty place holder (or just a default image) for the records which don't have an icon downloaded yet;
Make sure you're synchronizing your model (QMutex QSemaphore QWaitCondition)
hope this helps, regards
Related
Currently im working on a complex program that parse large nested json into a tree and display it. I created a tree to parse data and a model to query data from tree to display it in QML ListView.
Now i need to create a some kind of delegate provider for this model. Each element in tree have its own delegate with different set of options and different qml items. And there must be an option to load new type of delegates in the runtime.
Is there are nice solution to do that? Some kind of custom C++ Loader component? I need an advise. I already know that it can be done using switch case and qml loader. But this solution is not acceptable for me.
I am attempting to implement the Daydream keyboard into an app built in Unity and am not able to get this to work. I have added the keyboard prefab as a sibling of the main camera and added two input fields with the onpointerclick function added as instructed. I however get a null reference exception and assume this is due to the daydream keyboard delegate field being blank. The example scene in the SDK shows the daydream delegate example prefab but I am unsure how to implement this for two input fields. Also does the keyboard render in the Unity editor or must it be built and run on a phone?
This is an old question and has probably already been answered, but I figured I'd publicize my answer anyway.
For those reading, if you haven't checked out the Keyboard Demo scene that can be found within the Demos folder of the Google VR Unity package, I would highly recommend doing so. Following this object hierarchy has worked for me in the past.
To answer your first question, it seems that they have included a KeyboardDelegateExample object within the scene's hierarchy, and then used this object as the Keyboard Delegate in the GVRKeyboardManager.
They manage to fake an Input Field by creating a background and overlaying a Text object on top. If this method does not suffice and using an Input Field is crucial in your particular case, then drop your Input Fields into two separate GVRKeyboardCanvas objects.
Clicking on either canvas will activate the GVR Keyboard. You may have to add a small script to manage the transitioning of the input field.
Lastly, no the GVR Keyboard does not render in the Unity Editor, it only appears while running a build. Hopefully this will be addressed in later releases. There are also Keyboard plugins that you may find useful on the Asset Store.
I would like to know what the established procedure is for initializing the controls within a Qt custom dialog box. In the code I am writing, the dialog would present a QListView containing directories from an object passed (by reference) to the dialog class during construction. When the dialog is displayed, I obviously want the list to display the directories currently configured in the object.
Where should this be done though? Perhaps in the overridden showEvent() method?
Background: I used to do a lot of MFC programming back in the day, and would have done this sort of stuff in the OnCreate method, or some such, once the window object had been created.
Thankfully Qt doesn't require you to do any hooking to find the moment to create things (unless you want to). If you look over the Qt examples for dialogs, most do all the constructing in the constructor:
http://doc.qt.io/archives/qt-4.7/examples-dialogs.html
The tab dialog example--for instance--doesn't do "on-demand" initializing of tabs. Although you could wire something up via the currentChanged signal:
http://doc.qt.io/archives/qt-4.7/qtabwidget.html#currentChanged
Wizard-style dialogs have initializePage and cleanupPage methods:
http://doc.qt.io/archives/qt-4.7/qwizardpage.html#initializePage
http://doc.qt.io/archives/qt-4.7/qwizardpage.html#cleanupPage
But by and large, you can just use the constructor. I guess the main exception would be if find yourself allocating the dialog at a much earlier time from when you actually display it (via exec), and you don't want to bear the performance burden for some part of that until it's actually shown. Such cases should be rare and probably the easiest thing to do is just add your own function that you call (like finalizeCreationBeforeExec).
I am naive to Qt and GUI programming.
Qt jpg image display
The procedure given for displaying an image is working fine and thank you for providing that. But I want to display an image when I click on radiobutton.
I created a slot, and I connected the button click event to the slot (dispImage is my slot). My slot consists only the code which is working to display an image (First answer in this link).
I am able to compile it and run it. But the o/p is not as we desire.
On button click, image window flashes for a sec and disappears.
One more point to share is, I tried the same with windowsflags example present in qt examples.
In this example I want to display the image on the preview window created by us. Even this is also not worked for me.
Please provide me the solution.
Thanks in advance.
This is happening because the method that you're connecting to the slot is creating all of the objects needed to display the image on the stack and they're going out of scope and being destroyed when that method returns. The linked example has the event loop running at the end of the method, so the objects don't go out of scope until the program exits.
You can fix this by making the necessary objects member variables of a class that has application lifetime.
Stu's answer above is correct.
If you don't understand what he's talking about, you may want to get a little bit more familiar with C++ before jumping into Qt. The example you are citing is different from what you are trying to do. It's a main() function whose stack variables aren't going to go out of scope until the process exits (that's when main() returns). The stack variables in a method go out of scope as soon as the method returns.
Using the example you cite as a template for your method, you need to declare the QGraphicsView object as a class variable in the header file for your radioslot object. This will make it so it stays in scope until your radioslot object is destroyed.
I'm working on implementing a virtual keyboard for a QtWebKit based browser. I'm having a lot of difficulty understanding how QtWebKit paints the controls within the actual page. Initially I thought they were QLineEdit instances, but they are not. Diving into implementation it appears that the glue code between Qt and WebKit paints the text field using QStyle and QPainter. Unfortunately, I'm very new to Qt and so I dont understand where in the event loop the mouse presses for these events are interpreted. I found Editor::canEdit() deep in the call stack, and now I can bring up the virtual keyboard when the user clicks on a text field within the page. The virtual keyboard then expected a pointer to a QWidget instance, but Edito::canEdit() doesn't carry that information and I can't find anywhere where a QWidget like instance is exposed. I'm really stumped, any advice would be most welcome.
Thanks!
You might get better luck by hooking the virtual keyboard into the Qt input method system. Search for "InputMethod" in the source code of QtWebKit Api, i.e. the qweb*.* files.