Double Values rounded down when I use function within my mainwindow



  • 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


  • Qt Champions 2016

    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 ?



  • 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


  • Qt Champions 2016

    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.



  • 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


  • Qt Champions 2016

    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.



  • 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


  • Qt Champions 2016

    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.



  • 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.



  • 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 !!!!!!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.