Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QStringList number of items?
Forum Updated to NodeBB v4.3 + New Features

QStringList number of items?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 27.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    chronix
    wrote on last edited by
    #1

    Is there a way to find the number of items in the QStringList?

    1 Reply Last reply
    0
    • mranger90M Offline
      mranger90M Offline
      mranger90
      wrote on last edited by
      #2

      http://qt-project.org/doc/qt-5.0/qtcore/qstringlist-members.html

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        Do you mean something like size() ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • C Offline
          C Offline
          chronix
          wrote on last edited by
          #4

          [quote author="SGaist" date="1377015633"]Hi,

          Do you mean something like size() ?[/quote]

          No not like size.
          lets say we have a
          QStringList fonts;
          fonts << "Arial" << "Helvetica" << "Times" << "Courier";

          QString f1;
          f1 = fonts[0];
          QString f2;
          f2 = font[1];

          now f1 will be Arial and f2 will Helvetica.
          So technically, QStringList fonts has 4 items.
          so like this can i find the max number of items the QStringList has

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mcaiioe3
            wrote on last edited by
            #5

            QStringList inherits from QList<QString>
            QList has two methods to count the number of items in the list,
            int QList::size() const & int QList::count() const.

            Example:-
            QStringList list;
            list << "a" <<"b" <<"c" <<"d" << "e" << "f";
            qDebug() << list.count(); //or list.size(); ======> 6

            There is another version for count(), whic is
            int QList::count(const T & value) const
            this one returns the number of occurrences of value in the list.

            Example:-
            QStringList list;
            list << "a" << "c" << "a" << "f" << "a" << "a" << "b";
            qDebug() << list.count("a"); =====> 4

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved