Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Double Values rounded down when I use function within my mainwindow

Double Values rounded down when I use function within my mainwindow

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 3 Posters 1.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    NatalieKubiicki
    wrote on last edited by
    #1

    Hey,

    I am trying to write a Qt application which can simply visualize atoms of a molecules. For that I am using Qt with opengl and I just create many spheres with opengl.

    But now I have a very confusing problem with loading my data because if call the read function from my geometry object to read the data out from a pdb file , the data is rounded down if I create the object in my Mainwindow. If I simply create an object in my main and call there the read and print function everything works correct and i get my double values. Here is a picture of my code if I should upload the complete code i can also do it but i think this is a general basic problem but I can't figure it out by myself. I hope anyone has an Idea why the values are rounded up, thank you for your help!
    0_1508076160878_Bildschirmfoto vom 2017-10-15 15-58-16.png

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi
      It should not matter from where you call it.
      in first example geom g; is local variable

      in other sample you seems to have new it.
      (im gusing in mainwindow constructor ?)

      can we see g::print_variable ?

      1 Reply Last reply
      1
      • N Offline
        N Offline
        NatalieKubiicki
        wrote on last edited by
        #3

        Hey thank you for your answer!
        The problem is i get if i try in my main.cpp
        geom * g = new geom;
        ..
        g->print_variable();
        also the correct double values ..

        0_1508080196460_mainwindow.png
        0_1508080199454_printdata.png

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi
          Sorry cant guess. i see nothing in the code that would
          do anything differently from running in main.

          Except in mainwindow you
          create geom in one place and use in other.
          Make sure its really is the same you new and use.

          Also, please inspect the actual variables to make sure its just not a
          output fail. They really are capped as values.

          1 Reply Last reply
          0
          • N Offline
            N Offline
            NatalieKubiicki
            wrote on last edited by
            #5

            Nevertheless thank you for your help, I have never had a problem like this and tried so many things but dont understand why there are always the wrong values
            In the picture you can see again that i also get the wrong values if i create a local object
            0_1508081130662_problem.png

            1 Reply Last reply
            0
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              So
              If you have exact same code in mainwindow as in main,
              you get different values?
              and you did check with debugger they are wrong ?
              and nothing with cout.

              1 Reply Last reply
              1
              • N Offline
                N Offline
                NatalieKubiicki
                wrote on last edited by
                #7

                Wow now I am really confused but you were right if i let the program run with the debugger it works !!0_1508083995652_Bildschirmfoto vom 2017-10-15 18-11-22.png
                But why does not it work if i just let it normally run? then i get again the wrong values ? I can see it that i get the wrong values because my molecule looks different ( wrong) contrary to the molecule when i run the program with the debugger (right values) , do you have a an idea why the debugger run works )!0_1508084237746_wrongwithoutdebugger.png 0_1508084241198_rightwithdebugger.png

                1 Reply Last reply
                0
                • mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Hi
                  Well just so im sure i understand it.

                  it works if you run with debugger but dont stop anywhere but simply run it in debug mode ?
                  but if you just run it, it dont ?
                  (both being debug builds)

                  Unless something goes out of scope I cant explain it since it just works in
                  main and geom seems not to know anything about mainwindow.

                  you should single step your code and see what is doing the capping.

                  1 Reply Last reply
                  1
                  • aha_1980A Offline
                    aha_1980A Offline
                    aha_1980
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    hello,
                    when run in the debugger, LC_NUMERIC is set to"C". Some std library functions expect comma (,) instead decimal point (.) if that is not the case. that would explain why the program works in debug mode but not otherwise.

                    try adding LC_NUMERIC="C" to the run environment and test again.

                    Qt has to stay free or it will die.

                    1 Reply Last reply
                    2
                    • N Offline
                      N Offline
                      NatalieKubiicki
                      wrote on last edited by
                      #10

                      Thank you so much it works now and runs normal when I write
                      #include "mainwindow.h"
                      #include <QApplication>
                      #include <GL/glut.h>
                      #include "geometry.h"

                      int main(int argc, char *argv[])
                      {

                      glutInit(&argc, argv);
                      QApplication a(argc, argv);
                      setlocale(LC_NUMERIC,"C"); 
                      MainWindow w;
                      w.show();
                      
                      return a.exec();
                      

                      }

                      Thank you !!!!!!

                      1 Reply Last reply
                      1

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved