Results 1 to 5 of 5

Thread: While statement inside the main loop

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Default Re: While statement inside the main loop

    Well, I'm not really trying to do anything with the label, it was just there for testing purposes. I figured that if I could get that label to work right, then I could get whatever else I wanted to put in the while statement to work. In reality, I'll be using this code:
    Qt Code:
    1. while (i)
    2. {
    3. int amp = window.slider->ampSlider->value();
    4. int freq = window.slider->freqSlider->value();
    5. int sineValue = amp * ( sin(2 * M_PI * freq) * i);
    6. i++;
    7. }
    To copy to clipboard, switch view to plain text mode 
    Or at least something similar to it. In other words, I want it to be giving me the y axis of a sine wave while the program runs, so that it lets me change the amplitude and the frequency using the slider, and updates the sine wave accordingly. The i is there so the sine wave moves along the x axis, resulting in a smooth up and down motion.

  2. #2
    Join Date
    Jan 2006
    Location
    Athens - Greece
    Posts
    219
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: While statement inside the main loop

    Quote Originally Posted by OnionRingOfDoom
    Well, I'm not really trying to do anything with the label, it was just there for testing purposes. I figured that if I could get that label to work right, then I could get whatever else I wanted to put in the while statement to work. In reality, I'll be using this code:
    Qt Code:
    1. while (i)
    2. {
    3. int amp = window.slider->ampSlider->value();
    4. int freq = window.slider->freqSlider->value();
    5. int sineValue = amp * ( sin(2 * M_PI * freq) * i);
    6. i++;
    7. }
    To copy to clipboard, switch view to plain text mode 
    I 'd suggest a timer and updating the graph each time it times out. Don't use the while loop especially since it's not necessary as the event loop will be blocked and you'll have to processEvents() if you use it.

    Edit: I only show the last post and Weaver has suggested the same thing

Similar Threads

  1. HAL & DBusConnection & Qt main loop integration
    By juannm in forum Qt Programming
    Replies: 3
    Last Post: 15th January 2009, 08:06
  2. Replies: 4
    Last Post: 26th June 2008, 18:41
  3. Main Thread Event loop
    By ^NyAw^ in forum Qt Programming
    Replies: 1
    Last Post: 20th March 2007, 12:10
  4. Workload in a QThread blocks main application's event loop ?
    By 0xBulbizarre in forum Qt Programming
    Replies: 14
    Last Post: 9th April 2006, 21:55

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.