Ctor connects a pushbutton click with QtDice::reload which in turn calls QtDice::image_update to animate the gif and after it's finished, show an image.
I found out what the problem is. QtDice::image_update is called multiple times and therefore it tries to setFileName every time. So a check if fileName() is empty must be done each time before attempting to setFileName.
void QtDice::image_update(int image_number)
//Make sure we don't constantly re-append a fileName!
if(movie->fileName() == "" )
//If it still is empty print error and exit. Not good at all
//TODO wrap the setFileName in some Qt assert to throw an exception
if (movie->fileName() == "")
qDebug() << "Error! Couldn't set a fileName to read for the animation";
I don't know exactly why this failed ( I mean I could change the fileName as many times as I like), but I checked and rechecked that with this if (movie->fileName() == "" ).... the animation works.
That could also explain why some (but not all) times the animation played the very first time I push the button (ie called the function) and the second time it stopped. If someone thinks that other reasons come into play, please inform me, I am more than glad to learn.
For any of you, that is curious what is the code and/or want to c&c, this is the QtDice and this is a screenshot
Also to be more specific, this is part of a setup/initialization-code so this objects and connections are created once during startup, so I should not flood the memory. The main loop of widgets is about 10 in size.
But I see your point about the switch statement, I could wrap everything up in one connect-statement, but than I would have to create the 3 different Icons berforehand, to refer them correctly in the lambda.
I may do that, was never a fan of switches in loops myself either.
Like i said, i think you can built your own class by inherit from QModbusDevice to have a synchronous API. The QSerialBus module is marked as technical preview in Qt 5.6, maybe they add some new functions in future releases similar to QTcpSocket like waitForConnected etc.
Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.