Results 1 to 5 of 5

Thread: display an array of integers

  1. #1
    Join Date
    Jan 2016
    Posts
    22
    Thanks
    13

    Default display an array of integers

    Hello,
    i want to display an array of integers, how can i do that please?
    Thank you.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: display an array of integers

    There are so many ways that you will need to be a bit more precise on what you need.

    Cheers,
    _

  3. #3
    Join Date
    Jan 2016
    Posts
    22
    Thanks
    13

    Default Re: display an array of integers

    i want to code a merge sort algorithm, but just to start i want to display for example a QVector of 10 elements, just for the interface
    i want to display this vector
    Qt Code:
    1. #include <QApplication>
    2. #include <QtWidgets>
    3.  
    4.  
    5. int main(int argc, char *argv[])
    6. {
    7. QApplication app(argc, argv);
    8. QVector<int> vector(5);
    9. for (int i=0;i< vector.size(); i++)
    10. {
    11. vector[i]=i;
    12. }
    13.  
    14.  
    15.  
    16.  
    17. f.show();
    18. return app.exec();
    19.  
    20. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by rafik; 4th February 2016 at 19:49.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: display an array of integers

    The easiest way I can think of is to create a string that contains all numbers and display that in a QLabel
    Qt Code:
    1. foreach (const int number, vector) {
    2. items << QString::number(number);
    3. }
    4. label->setText(items.join(", "));
    To copy to clipboard, switch view to plain text mode 

    Alternatively with a QListWidget
    Qt Code:
    1. foreach (const int number, vector) {
    2. listWidget->addItem(QString::number(number));
    3. }
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  5. The following user says thank you to anda_skoa for this useful post:

    rafik (6th February 2016)

  6. #5
    Join Date
    Jan 2016
    Posts
    22
    Thanks
    13

    Default Re: display an array of integers

    Thank you Mr anda, with your second example QListWidget i get what i want. thanks

Similar Threads

  1. Char array[6] to QString and display it
    By arunvv in forum Newbie
    Replies: 11
    Last Post: 12th March 2014, 21:48
  2. Replies: 2
    Last Post: 5th December 2013, 12:10
  3. Display my data array as an image
    By OzQTNoob in forum Newbie
    Replies: 5
    Last Post: 4th December 2012, 10:17
  4. QGraphicsView (using int array) advice and display help
    By enricong in forum Qt Programming
    Replies: 4
    Last Post: 11th April 2012, 14:40
  5. Display an image from a unsigned char array
    By Percy in forum Qt Programming
    Replies: 1
    Last Post: 1st December 2009, 21:16

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.