Results 1 to 4 of 4

Thread: how to do this ?

  1. #1
    Join Date
    Jan 2010
    Posts
    63
    Qt products
    Qt4
    Platforms
    Windows

    Default how to do this ?

    I am writing a widget to display prime numbers.
    How can i output the list of say first 1000 primes in Qt ?
    ex code
    Qt Code:
    1. for(prime=1;prime<1000;++primes)
    2. cout<<primes<<endln
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to do this ?

    Depends on what you want. You can put them in a QLabel or in a QStringListModel that is read by QListView.
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  3. #3
    Join Date
    Jan 2010
    Posts
    63
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to do this ?

    Readout should look like
    1
    3
    5
    7
    11
    .
    .
    .
    .
    997

    Qlabel doesn't allow for scroll as far as I looked at the functions.
    QStringListModel probablly then .
    Maybe if the list primes is read into an array or something.

  4. #4
    Join Date
    Oct 2009
    Posts
    151
    Thanks
    6
    Thanked 13 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to do this ?

    Is this what you want?

    Qt Code:
    1. QList<QString> primes;
    2. primes << 1 << 2 << 3 << 5 << 7;
    3.  
    4. for (int i = 0; i < primes.size(); ++i) cout << primes.at(i) << endl;
    To copy to clipboard, switch view to plain text mode 


    if your programme is running from the command line, the output will probably be to the screen.
    Under QT the output is likely to appear in the debug area.

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.