返回介绍

QStrList Class

发布于 2019-10-04 15:03:05 字数 3061 浏览 848 评论 0 收藏 0

The QStrList class provides a doubly-linked list of char*. More...

#include <qstrlist.h>

Inherits QPtrList<char>.

Inherited by QStrIList.

List of all member functions.

Public Members

  • QStrList ( booldeepCopies = TRUE )
  • QStrList ( constQStrList&list )
  • ~QStrList ()
  • QStrList & operator= ( constQStrList&list )

Detailed Description

The QStrList class provides a doubly-linked list of char*.

If you want a string list of QStrings use QStringList.

This class is a QPtrList<char> instance (a list of char*).

QStrList can make deep or shallow copies of the strings that are inserted.

A deep copy means that memory is allocated for the string and then the string data is copied into this memory. A shallow copy is just a copy of the pointer value and not of the string data itself.

The disadvantage of shallow copies is that because a pointer can be deleted only once, the program must put all strings in a central place and know when it is safe to delete them (i.e. when the strings are no longer referenced by other parts of the program). This can make the program more complex. The advantage of shallow copies is that shallow copies consume far less memory than deep copies. It is also much faster to copy a pointer (typically 4 or 8 bytes) than to copy string data.

A QStrList that operates on deep copies will, by default, turn on auto-deletion (see setAutoDelete()). Thus, by default QStrList will deallocate any string copies it allocates.

The virtual compareItems() function is reimplemented and does a case-sensitive string comparison. The inSort() function will insert strings in a sorted order. In general it is fastest to insert the strings as they come and sort() at the end; inSort() is useful when you just have to add a few extra strings to an already sorted list.

The QStrListIterator class is an iterator for QStrList.

See also Collection Classes, Text Related Classes and Non-GUI Classes.


Member Function Documentation

QStrList::QStrList ( booldeepCopies = TRUE )

Constructs an empty list of strings. Will make deep copies of all inserted strings if deepCopies is TRUE, or use shallow copies if deepCopies is FALSE.

QStrList::QStrList ( constQStrList&list )

Constructs a copy of list.

If list has deep copies, this list will also get deep copies. Only the pointers are copied (shallow copy) if the other list does not use deep copies.

QStrList::~QStrList ()

Destroys the list. All strings are removed.

QStrList& QStrList::operator= ( constQStrList&list )

Assigns list to this list and returns a reference to this list.

If list has deep copies, this list will also get deep copies. Only the pointers are copied (shallow copy) if the other list does not use deep copies.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文