⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qptrlist.html

📁 QT3的教程
💻 HTML
📖 第 1 页 / 共 3 页
字号:

<h3 class=fn><a name="QPtrList-2"></a>QPtrList::QPtrList ( const&nbsp;<a href="qptrlist.html">QPtrList</a>&lt;type&gt;&nbsp;&amp;&nbsp;list )
</h3>
构造一个<em>list</em>的复制。
<p> <em>list</em>的每一个项都<a href="#append">被添加</a>到这个列表中。只有指针被复制(浅复制)。

<h3 class=fn><a name="~QPtrList"></a>QPtrList::~QPtrList ()
</h3>
移除列表中的所有项并且销毁这个列表。
<p> 访问这个列表的所有列表迭代器都会被重置。
<p> <p>也可以参考<a href="qptrcollection.html#setAutoDelete">setAutoDelete</a>()。

<h3 class=fn>void <a name="append"></a>QPtrList::append ( const&nbsp;type&nbsp;*&nbsp;item )
</h3>
在列表的最后插入<em>item</em>。
<p> 被插入的项变为当前列表项。这和<tt>insert( count(), item )</tt>是相同的。
<p> <em>item</em>必须不是一个空指针。
<p> <p>也可以参考<a href="#insert">insert</a>()、<a href="#current">current</a>()和<a href="#prepend">prepend</a>()。
<p>实例:<a href="customlayout-example.html#x1371">customlayout/border.cpp</a>、<a href="customlayout-example.html#x1389">customlayout/card.cpp</a>、<a href="customlayout-example.html#x1348">customlayout/flow.cpp</a>、<a href="grapher-nsplugin-example.html#x2778">grapher/grapher.cpp</a>、<a href="listviews-example.html#x347">listviews/listviews.cpp</a>、<a href="listviews-example.html#x318">listviews/listviews.h</a>和<a href="qwerty-example.html#x385">qwerty/qwerty.cpp</a>。

<h3 class=fn>type * <a name="at"></a>QPtrList::at ( uint&nbsp;index )
</h3>
返回一个在列表<em>index</em>位置的项的指针,如果索引超出范围,返回空。
<p> 如果<em>index</em>有效,设置这个项为当前列表项。有效范围是<tt>0……(count() - 1)</tt>。
<p> 这个函数是非常有效的。它从第一项、最后一项或当前项中最接近<em>index</em>的开始扫描。
<p> <p>也可以参考<a href="#current">current</a>()。
<p>实例:<a href="customlayout-example.html#x1372">customlayout/border.cpp</a>、<a href="customlayout-example.html#x1390">customlayout/card.cpp</a>、<a href="customlayout-example.html#x1349">customlayout/flow.cpp</a>、<a href="dirview-example.html#x1737">dirview/dirview.cpp</a>、<a href="fileiconview-example.html#x863">fileiconview/qfileiconview.cpp</a>、<a href="mdi-example.html#x2035">mdi/application.cpp</a>和<a href="qwerty-example.html#x386">qwerty/qwerty.cpp</a>。

<h3 class=fn>int <a name="at-2"></a>QPtrList::at () const
</h3>
这是一个重载成员函数,提供了方便。它的行为基本上和上面的函数相同。
<p> 返回当前列表项的索引。如果当前项为空,返回值为-1。
<p>也可以参考<a href="#current">current</a>()。

<h3 class=fn>bool <a name="autoDelete"></a>QPtrCollection::autoDelete () const
</h3>
<p> 返回自动删除选项的设置。默认为假。
<p> <p>也可以参考<a href="qptrcollection.html#setAutoDelete">setAutoDelete</a>()。

<h3 class=fn>void <a name="clear"></a>QPtrList::clear ()<tt> [虚]</tt>
</h3>
移除列表中所有项。
<p> 如果<a href="qptrcollection.html#setAutoDelete">自动删除</a>生效,被移除的项目将被删除。
<p> 所有访问这个列表的列表迭代器都将被重置。
<p> <p>也可以参考<a href="#remove">remove</a>()、<a href="#take">take</a>()和<a href="qptrcollection.html#setAutoDelete">setAutoDelete</a>()。
<p>从<a href="qptrcollection.html#clear">QPtrCollection</a>中重新实现。

<h3 class=fn>int <a name="compareItems"></a>QPtrList::compareItems ( <a href="qptrcollection.html#Item">QPtrCollection::Item</a>&nbsp;item1, <a href="qptrcollection.html#Item">QPtrCollection::Item</a>&nbsp;item2 )<tt> [虚 保护]</tt>
</h3>
<p> 这个虚函数比较两个列表项。
<p> 返回:
<ul>
<li> 如果<em>item1</em>==<em>item2</em>,返回0
<li> 如果<em>item1</em>!=<em>item2</em>,返回非0
</ul>
<p> 这个函数返回<em>int</em>而不是<em>bool</em>,这样可以重新实现返回三个值并且使用它来排序:
<p> <ul>
<li> 如果<em>item1</em> == <em>item2</em>,返回0
<li> 如果<em>item1</em>&gt;<em>item2</em>,返回&gt;0(正整数)
<li> 如果<em>item1</em>&lt;<em>item2</em>,返回&lt;0(负整数)
</ul>
<p> <a href="#inSort">inSort</a>()需要<a href="#compareItems">compareItems</a>()像这里所描述的这样来被实现。
<p> 这个函数不应该修改列表,因为一些常量函数调用compareItems()。
<p> 默认实现是比较指针。

<h3 class=fn>uint <a name="contains"></a>QPtrList::contains ( const&nbsp;type&nbsp;*&nbsp;item ) const
</h3>
计算并且返回<em>item</em>在列表中出现的次数。
<p> 当在列表中搜索<em>item</em>时,<a href="#compareItems">compareItems</a>()函数被调用。如果compareItems()没有被重新实现,调用<a href="#containsRef">containsRef</a>()是更有效率的。
<p> 这个函数不影响当前列表项。
<p> <p>也可以参考<a href="#containsRef">containsRef</a>()和<a href="#compareItems">compareItems</a>()。

<h3 class=fn>uint <a name="containsRef"></a>QPtrList::containsRef ( const&nbsp;type&nbsp;*&nbsp;item ) const
</h3>
计算并且返回<em>item</em>在列表中出现的次数。
<p> 调用这个函数比<a href="#contains">contains</a>()快多了,因为contains()使用<a href="#compareItems">compareItems</a>()来用<em>item</em>与列表中的每一个项进行比较。这个函数只比较指针。
<p> 这个函数不影响当前列表项。
<p> <p>也可以参考<a href="#contains">contains</a>()。

<h3 class=fn>uint <a name="count"></a>QPtrList::count () const<tt> [虚]</tt>
</h3>
返回列表中项的数量。
<p>也可以参考<a href="#isEmpty">isEmpty</a>()。
<p>实例:<a href="customlayout-example.html#x1373">customlayout/border.cpp</a>、<a href="customlayout-example.html#x1391">customlayout/card.cpp</a>、<a href="customlayout-example.html#x1350">customlayout/flow.cpp</a>、<a href="fileiconview-example.html#x864">fileiconview/qfileiconview.cpp</a>、<a href="grapher-nsplugin-example.html#x2779">grapher/grapher.cpp</a>、<a href="mdi-example.html#x2036">mdi/application.cpp</a>和<a href="qwerty-example.html#x387">qwerty/qwerty.cpp</a>。
<p>从<a href="qptrcollection.html#count">QPtrCollection</a>中重新实现的。

<h3 class=fn>type * <a name="current"></a>QPtrList::current () const
</h3>
返回一个指向当前列表项的指针。当前列表项可能为空(意味着当前索引为-1)。
<p>也可以参考<a href="#at">at</a>()。

<h3 class=fn>QLNode * <a name="currentNode"></a>QPtrList::currentNode () const
</h3>
返回指向当前列表节点的指针。
<p> 节点可以被保存并且稍后使用<a href="#removeNode">removeNode</a>()移除。这样做的优点是可以直接移除这个项,而不用搜索列表。
<p> <b>警告:</b>不要调用这个函数,除非你是专家。
<p> <p>也可以参考<a href="#removeNode">removeNode</a>()、<a href="#takeNode">takeNode</a>()和<a href="#current">current</a>()。

<h3 class=fn>int <a name="find"></a>QPtrList::find ( const&nbsp;type&nbsp;*&nbsp;item )
</h3>
找到<em>item</em>在列表中第一次出现的位置。
<p> 如果这个项被找到,列表会设置当前项指向找到的项,并且返回这个项的索引。如果没有被找到,列表设置当前项为空,当前索引为-1,并且返回-1。
<p> 当在列表中搜索这个项时,<a href="#compareItems">compareItems</a>()函数被调用。如果compareItems()没有被重新实现,调用<a href="#findRef">findRef</a>()是更有效率的。
<p> <p>也可以参考<a href="#findNext">findNext</a>()、<a href="#findRef">findRef</a>()、<a href="#compareItems">compareItems</a>()和<a href="#current">current</a>()。

<h3 class=fn>int <a name="findNext"></a>QPtrList::findNext ( const&nbsp;type&nbsp;*&nbsp;item )
</h3>
从当前列表项,找到<em>item</em>在列表中下一次出现的位置。
<p> 如果这个项被找到,列表会设置当前项指向找到的项,并且返回这个项的索引。如果没有被找到,列表设置当前项为空,当前索引为-1,并且返回-1。
<p> 当在列表中搜索这个项时,<a href="#compareItems">compareItems</a>()函数被调用。如果compareItems()没有被重新实现,调用<a href="#findNextRef">findNextRef</a>()是更有效率的。
<p> <p>也可以参考<a href="#find">find</a>()、<a href="#findNextRef">findNextRef</a>()、<a href="#compareItems">compareItems</a>()和<a href="#current">current</a>()。

<h3 class=fn>int <a name="findNextRef"></a>QPtrList::findNextRef ( const&nbsp;type&nbsp;*&nbsp;item )
</h3>
从当前列表项,找到<em>item</em>在列表中下一次出现的位置。
<p> 如果这个项被找到,列表会设置当前项指向找到的项,并且返回这个项的索引。如果没有被找到,列表设置当前项为空,当前索引为-1,并且返回-1。
<p> 调用这个函数比<a href="#findNext">findNext</a>()快得多,因为findNext()是使用<a href="#compareItems">compareItems</a>()来用<em>item</em>与列表中的每一个项进行比较。这个函数只比较指针。
<p> <p>也可以参考<a href="#findRef">findRef</a>()、<a href="#findNext">findNext</a>()和<a href="#current">current</a>()。

<h3 class=fn>int <a name="findRef"></a>QPtrList::findRef ( const&nbsp;type&nbsp;*&nbsp;item )
</h3>
找到<em>item</em>在列表中第一次出现的位置。
<p> 如果这个项被找到,列表会设置当前项指向找到的项,并且返回这个项的索引。如果没有被找到,列表设置当前项为空,当前索引为-1,并且返回-1。
<p> 调用这个函数比<a href="#find">find</a>()快得多,因为find()是使用<a href="#compareItems">compareItems</a>()来用<em>item</em>与列表中的每一个项进行比较。这个函数只比较指针。
<p> <p>也可以参考<a href="#findNextRef">findNextRef</a>()、<a href="#find">find</a>()和<a href="#current">current</a>()。

<h3 class=fn>type * <a name="first"></a>QPtrList::first ()
</h3>
返回指向列表中第一个项的指针并且使它成为当前列表项,或者如果列表为空当前项就为空。
<p>也可以参考<a href="#getFirst">getFirst</a>()、<a href="#last">last</a>()、<a href="#next">next</a>()、<a href="#prev">prev</a>()和<a href="#current">current</a>()。
<p>实例:<a href="grapher-nsplugin-example.html#x2780">grapher/grapher.cpp</a>、<a href="listviews-example.html#x319">listviews/listviews.h</a>和<a href="showimg-example.html#x1281">showimg/showimg.cpp</a>。

<h3 class=fn>type * <a name="getFirst"></a>QPtrList::getFirst () const
</h3>
返回指向列表中第一个项的指针,如果列表为空返回空。
<p> 这个函数不影响当前列表项。
<p> <p>也可以参考<a href="#first">first</a>()和<a href="#getLast">getLast</a>()。

<h3 class=fn>type * <a name="getLast"></a>QPtrList::getLast () const
</h3>
Returns a pointer to the last item in the list, or null if the
list is empty.
返回指向列表中最后一个项的指针,如果列表为空返回空。
<p> 这个函数不影响当前列表项。
<p> <p>也可以参考<a href="#last">last</a>()和<a href="#getFirst">getFirst</a>()。

<h3 class=fn>void <a name="inSort"></a>QPtrList::inSort ( const&nbsp;type&nbsp;*&nbsp;item )
</h3>
把<em>item</em>插入到列表中它被排序的位置。
<p> 排序依靠的是虚函数<a href="#compareItems">compareItems</a>()。为了维护这个派逊,所有的项都必须使用<a href="#inSort">inSort</a>()来插入。
<p> 被插入的项变为当前项。
<p> <em>item</em>必须不能是一个空指针。
<p> 请注意inSort()很慢。如果你想先向列表插入很多项,插入完之后再排序,你应该使用<a href="#sort">sort</a>()。inSort()进行了O(n)次比较。这就意味着插入n个项到你的列表需要比较O(n^2)次,而sort()做同样的工作只需要O(n*log n)次。所以只有在你有一个预先排好序的列表并且想向其中插入少量的项时,再使用inSort()。
<p> <p>也可以参考<a href="#insert">insert</a>()、<a href="#compareItems">compareItems</a>()、<a href="#current">current</a>()和<a href="#sort">sort</a>()。

<h3 class=fn>bool <a name="insert"></a>QPtrList::insert ( uint&nbsp;index, const&nbsp;type&nbsp;*&nbsp;item )
</h3>
插入<em>item</em>到列表的<em>index</em>位置。
<p> 如果成功返回真,或者如果<em>index</em>超出范围返回假。有效的范围是从0到<a href="#count">count</a>()(包括count())。如果<em>index</em>==count(),项就被添加。
<p> 被插入的项变为当前项。
<p> <em>item</em>必须不能是一个空指针。
<p> <p>也可以参考<a href="#append">append</a>()和<a href="#current">current</a>()。

<h3 class=fn>bool <a name="isEmpty"></a>QPtrList::isEmpty () const
</h3>
如果列表是空的,返回真,否则返回假。
<p> <p>也可以参考<a href="#count">count</a>()。

<h3 class=fn>type * <a name="last"></a>QPtrList::last ()
</h3>
返回指向列表最后一项的指针,并且把这一项变为当前列表项,如果列表为空,当前列表项为空。
<p>也可以参考<a href="#getLast">getLast</a>()、<a href="#first">first</a>()、<a href="#next">next</a>()、<a href="#prev">prev</a>()和<a href="#current">current</a>()。

<h3 class=fn>type * <a name="next"></a>QPtrList::next ()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -