Results 1 to 4 of 4

Thread: Passing QSpinBox::value() to a gloabal variable

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Passing QSpinBox::value() to a gloabal variable

    Is the slot getting called?
    If you do the connection correctly then there should be no problem here.

    You are getting the initial value of dimx because you're printing it too soon.
    You should do something like this to see the value assigned in the slot:
    Qt Code:
    1. QApplication app(argc, argv);
    2. MainWindow *mainWin=new MainWindow;
    3. [B]mainWin->show();
    4. [/B]
    5. int execRet = app.exec();
    6.  
    7. [B]std:: ofstream myfile;
    8. myfile.open ("data.txt");
    9. myfile<<dimx;
    10. myfile.close();
    11.  
    12. return execRet;
    13. [/B]
    To copy to clipboard, switch view to plain text mode 

    This is one way of doing it.
    You were saving the variable right after showing the
    window( show exits immediately), therefore it did not had the chance to get its new value.

    Generally, assigning to a static var should work, but you have to know when/where/if the var was modified prior to using it.

    Regards

  2. The following user says thank you to marcel for this useful post:

    adonis (8th June 2007)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.