Results 1 to 5 of 5

Thread: How to display the numbers in a QList<QString> ?

  1. #1
    Join Date
    Nov 2011
    Posts
    45
    Qt products
    Qt4
    Platforms
    Symbian S60

    Post How to display the numbers in a QList<QString> ?

    Hi all,
    I am trying to display the multiples of a number using QList<QString> but i was not able to do it on my own.


    In my coding when the user enters any number in the input it should display its multiple which means:for example,if the user enters number 4 the output should display the output as:4 8 12 16 20 24 28 32 36 40.

    Likewise whenever the user enters any number it should display the output.

    This is my code:

    void MainWindow:n_pushButton_clicked()
    {
    int result;
    bool ok;
    int n1 = ui->lineEdit->text().toInt(&ok,10);

    for (int i=1;i<= 10;i++)
    {
    result = n1 * i;
    QList<QString> list ;


    list << result;

    }

    I know that i am wrong somewhere anyone please help me with this?
    So that i can know the answer.

    Thanks in advance.



    Regards,
    Harish

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,462
    Thanked 271 Times in 266 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to display the numbers in a QList<QString> ?

    Every loop iteration creates new list. These are the basics of C++.

  3. #3
    Join Date
    Nov 2011
    Posts
    45
    Qt products
    Qt4
    Platforms
    Symbian S60

    Unhappy Re: How to display the numbers in a QList<QString> ?

    I know that every loop iteration creates new list but i am looking to display each and every value when printed.

    I had tried this one now:Is this right ?

    void MainWindow:n_pushButton_clicked()
    {
    int result;
    bool ok;
    int n1 = ui->lineEdit->text().toInt(&ok,10);
    QList<QString> list ;
    for (int i=1;i<= 10;i++)
    {
    result = n1 * i;
    QString str;
    str.append(QString("%1").arg(result));
    list << result;
    }

    It shows the error: invalid conversion from 'int' to 'const char*' .

    Any Solution for this?No one is there to help me?
    Last edited by harish; 2nd January 2012 at 12:10.

  4. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,462
    Thanked 271 Times in 266 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to display the numbers in a QList<QString> ?

    Bacuse QList<T> have only operator <<(const T & value). So for QList<QString> You can do only <<(QString) not <<(int).
    Your code should looks like :
    Qt Code:
    1. for (int i=1;i<= 10;i++)
    2. {
    3. result = n1 * i;
    4. list << QString::number(result);
    5. }
    To copy to clipboard, switch view to plain text mode 
    And please use CODE tags in Your post.

  5. #5
    Join Date
    Nov 2011
    Posts
    45
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: How to display the numbers in a QList<QString> ?

    Ok Lesiok thank you for your reply and i will use CODE tags from my post hereafter.

    Thank you again..

Similar Threads

  1. Replies: 1
    Last Post: 18th June 2011, 19:28
  2. I Want to sort QList<QMap<QString , qreal > >
    By amiref in forum Qt Programming
    Replies: 1
    Last Post: 7th May 2011, 14:33
  3. QList < QHash < int, QString> > ... clear() is slow
    By JoZCaVaLLo in forum Qt Programming
    Replies: 8
    Last Post: 15th March 2011, 12:07
  4. Replies: 3
    Last Post: 17th April 2010, 22:35
  5. How to use QLCDnumber to display negative numbers?
    By grissiom in forum Qt Programming
    Replies: 1
    Last Post: 19th March 2010, 07:23

Tags for this Thread

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.