Important: Please read the Qt Code of Conduct -

Qt for Android runs statements incorrectly

  • My app runs normally on my Linux laptop, but when I run it on an Android phone, it fails to correctly calculate some data if it is not a debug build.

    I have a hunch that it may be due to optimization; however, I haven't been able to debug a "Release with debug info" build since my debugger won't connect to the phone.

  • @LorenDB What kind of help do you expect without given at least a way to reproduce this nor giving with Qt version you have used?

  • @KroMignon oops, sorry! 😳 I was ready to sleep and trying to get something posted quickly, so I guess I forgot about that.

    My Qt version is 5.15.1. I'll try to get the code on GitHub and link back here post-haste.

  • My code is available at

  • @LorenDB
    That is large code, with no indication as to what goes wrong when. Don't know what help you expect with that. It is your job to cut that down to some minimal example which shows the issue.

    It is possible your code illustrates a bug in the compiler's optimizer. However, it is also possible that there is a bug in your code, which only shows up in Release, not Debug, build. If I were a betting man....

  • Indeed. Uninitialized variables are one common reason for this kind of things, and the code has at least one occurence of such.

  • @JonB I apologize, I should know better than to just post code and expect people to know what I mean. I'll try to do better in the future.

    @mvuori, @JonB: it turns out that my problem was an uninitialized variable.

    For the record:

    My problem was that when I entered some data into the data input and clicked the button (or pressed Enter), certain statistics such as the sum of the squares would not calculate correctly. It appeared that the mean was being calculated as zero (even though it wasn't). Initializing the accumulator in the calculateMean() function solved the problem. Thanks for the tip!

  • @LorenDB
    In practice, uninitialized variables can often have a different value in Debug vs Release builds, and be the cause of misbehaviour in one versus the other. They can be difficult to track down. I believe there are specialized tools to analyze code or do runtime detection for them, don't know if there is anything FOSS.

Log in to reply