I do apologize for the burstiness of these posts and sometimes skipping around. I don’t have much free time so I write these posts when something tends to piss me off or befuddle me. Today it was an animated gif.
I got that gif from Icons8. Yes, a site generating nice simple “loading” and/or “busy” animated gifs that are free to use and even has a little tool on the site that allows you to customize them before downloading is getting a plug. Just how cool is that?
So, I went the “standard” path of stuffing a QMovie into a QLabel like we’ve done for years in Qt. No love. Just a black box. This is when it hit me I was going to have to create a cs_gui_hello application. First I needed to verify I wasn’t suffering from old age and the effects of years of Chardonnay at night. I hop over to a Ubuntu 20.04 LTS machine and load whatever QtCreator was installed on it using whatever Qt version that it found.
Yes, many of you would just have a VM if you had that. I have multiple machines with multiple desks and some of the machines have multiple VMs. It’s how I roll. Honestly, it is because that is the way work comes in.
The tiger I bought when I was in college, deal with it. Whatever type of photography was in vogue then had a market and this looked cool. This is actually cleaned up office. Over the past year or so I’ve thrown out about four machines or so.
When clients want a custom Debian package that will install on N releases of Ubuntu but they are using high end features of library X so it can’t go in a Snap or any other low end container, you have to throw hardware at it. Finding the right combination of options and libraries to thread that needle can take weeks. It was even more fun when they wanted a .deb that would install on either 32-bit or 64-bit versions. Been there, done that, got the T-shirt.
So, first I need a GUI “Hello World” to verify what I believe to be true. After starting QtCreator I tell it to create a new project for me, Qt Widgets based. I put a File->Exit option on the main menu and endure the incredibly slow signal-slot editor connecting exit up to MainWindow::close(). I add two labels, one with “Hello World!” text and another big empty label I called movie_label.
Okay, I took the screenshot before I filled the menu in.
Adding a Resource File
This part is for the new people. Maybe you’ve only done QML so you don’t know Qt at all? Maybe you are new to the world of programming or just new to the world of Qt. I’m taking you down this detailed journey because even I had to poke a tiny bit. As more and more worthless (&()&* gets added to QtCreator (QML, Java, Python, etc.) it becomes harder and harder to find things.
I usually right click on the “Forms” in the window on the right. Theoretically you can right click on any of those entries for this. That wasn’t always the case or at least I remember a time that it wouldn’t work everywhere.
I never like the default prefix. Half of the time I just enter “/” but this time I chose “/animations.” After that I choose “Add Files” then navigated to a series of gif files with different colors and speeds.
Save and close the resource file once you have added your images or whatever.
Note: Just about anything can be in your resource file. For this Diamond editor I’m working on I stuck HTML help files in there. You kids who’ve never been more than six feet from an Internet connection need to learn the concepts of air-gapped and stand-alone. Machines on air-gapped networks have no Internet access. If you want help, all of the help has to be installed with the editor/IDE/whatever. The same is true for stand-alone because those machines aren’t even on a network.
Code wise, there isn’t much. I have always been a bit perturbed about parenting of QMovie objects. You either have to provide an empty QByteArray for the format to parent one or you have to construct the object with just a parent then assign the movie in another step. It would seem the could provide a constructor having a non-optional first parameter of parent. What is important is the QDebug statement.
You will note that this installation pulled from the Ubuntu repos only supports gif. Why this is important will be the subject of my next post.
To play the video below on my Ubuntu 20.04 LTS desktop I had to issue the following from the command line.
sudo apt install libdvdnav4 libdvdread7 gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly libdvd-pkg ubuntu-restricted-extras
Some browsers have their own codecs and such so might play video just fine. I was trying to look at the video locally before uploading to the post. If you can’t see it, then I guess you know what to try. It will also prompt you to run this command once.
sudo dpkg-reconfigure libdvd-pkg