QValueList类参考.docx

上传人:b****6 文档编号:8674881 上传时间:2023-02-01 格式:DOCX 页数:15 大小:21.37KB
下载 相关 举报
QValueList类参考.docx_第1页
第1页 / 共15页
QValueList类参考.docx_第2页
第2页 / 共15页
QValueList类参考.docx_第3页
第3页 / 共15页
QValueList类参考.docx_第4页
第4页 / 共15页
QValueList类参考.docx_第5页
第5页 / 共15页
点击查看更多>>
下载资源
资源描述

QValueList类参考.docx

《QValueList类参考.docx》由会员分享,可在线阅读,更多相关《QValueList类参考.docx(15页珍藏版)》请在冰豆网上搜索。

QValueList类参考.docx

QValueList类参考

QValueList类参考

QValueList类是一个提供基础值列表模版的类。

更多。

如果Qt是通过单一支持被建立的,此类中的所有方法是重入的。

#include

被QCanvasItemList,QStringList,和QValueStack继承.

所有成员列表

公有成员

typedefQValueListIteratoriterator

typedefQValueListConstIteratorconst_iterator

typedefTvalue_type

typedefvalue_type*pointer

typedefconstvalue_type*const_pointer

typedefvalue_type&reference

typedefconstvalue_type&const_reference

typedefsize_tsize_type

QValueList()

QValueList(constQValueList&l)

QValueList(conststd:

:

list&l)

~QValueList()

QValueList&operator=(constQValueList&l)

QValueList&operator=(conststd:

:

list&l)

booloperator==(conststd:

:

list&l)const

booloperator==(constQValueList&l)const

booloperator!

=(constQValueList&l)const

iteratorbegin()

const_iteratorbegin()const

iteratorend()

const_iteratorend()const

iteratorinsert(iteratorit,constT&x)

uintremove(constT&x)

voidclear()

QValueList&operator<<(constT&x)

size_typesize()const

boolempty()const

voidpush_front(constT&x)

voidpush_back(constT&x)

iteratorerase(iteratorit)

iteratorerase(iteratorfirst,iteratorlast)

referencefront()

const_referencefront()const

referenceback()

const_referenceback()const

voidpop_front()

voidpop_back()

voidinsert(iteratorpos,size_typen,constT&x)

QValueListoperator+(constQValueList&l)const

QValueList&operator+=(constQValueList&l)

iteratorfromLast()

const_iteratorfromLast()const

boolisEmpty()const

iteratorappend(constT&x)

iteratorprepend(constT&x)

iteratorremove(iteratorit)

T&first()

constT&first()const

T&last()

constT&last()const

T&operator[](size_typei)

constT&operator[](size_typei)const

iteratorat(size_typei)

const_iteratorat(size_typei)const

iteratorfind(constT&x)

const_iteratorfind(constT&x)const

iteratorfind(iteratorit,constT&x)

const_iteratorfind(const_iteratorit,constT&x)const

intfindIndex(constT&x)const

size_typecontains(constT&x)const

size_typecount()const

QValueList&operator+=(constT&x)

typedefQValueListIteratorIterator

typedefQValueListConstIteratorConstIterator

相关成员

QDataStream&operator>>(QDataStream&s,QValueList&l)

QDataStream&operator<<(QDataStream&s,constQValueList&l)

详细说明

QValueList类是一个提供基础值列表模版的类。

QValueList是一个Qt的STL的执行,像列表容器。

如果对于你的目标平台本身的列表是不可用的,它可以被用在你的应用程序中。

QValueList是QtTemplateLibrary的一部分。

QValueList定义一个模版的实例去创建一个可用的列表,全部含有T类。

注意QValueList

不储存列表成员的指针;它存储每一个成员的备份。

这就是为什么这些种类的类被称为“值基础”;QPtrList和QDict是“指针基础”。

QValueList包含并处理T类型对象的收集,支持允许包含对象被指向的迭代器。

QValueList包含自己的项。

对于更多不严格的所有权,见QPtrCollection和基础指针集装箱助手。

一些类不能在内部用QValueList。

例如,所有来自QObject的类和所有工具窗口部件的类。

只有值能用在QValueList中。

为了取得一个值的资格,这个类必须提供:

一个拷贝构造函数;

一个任务操作员;

一个默认构造函数,也就是,一个不带任何参数的构造函数。

注意C++默认要平均分配算子和拷贝构造函数如果不是当前版本会被替代。

在许多状况下是充足的。

QValueList的函数名和其他Qt类是一致的(例如:

count(),isEmpty())。

QValueList也提供例外的方法为了与STL法则兼容,像size()和empty()程序员已经熟悉STL列表更喜欢使用STL兼容的方法。

例如:

classEmployee

{

public:

Employee():

sn(0){}

Employee(constQString&forename,constQString&surname,intsalary)

:

fn(forename),sn(surname),sal(salary)

{}

QStringforename()const{returnfn;}

QStringsurname()const{returnsn;}

intsalary()const{returnsal;}

voidsetSalary(intsalary){sal=salary;}

private:

QStringfn;

QStringsn;

intsal;

};

typedefQValueListEmployeeList;

EmployeeListlist;

list.append(Employee("John","Doe",50000));

list.append(Employee("Jane","Williams",80000));

list.append(Employee("Tom","Jones",60000));

Employeemary("Mary","Hawthorne",90000);

list.append(mary);

mary.setSalary(100000);

EmployeeList:

:

iteratorit;

for(it=list.begin();it!

=list.end();++it)

cout<<(*it).surname().latin1()<<","<<

(*it).forename().latin1()<<"earns"<<

(*it).salary()<

//Output:

//Doe,Johnearns50000

//Williams,Janeearns80000

//Hawthorne,Maryearns90000

//Jones,Tomearns60000

注意最后的改变,玛利的薪水没有影响这个列表的值,因为这个列表创建了玛利项的副本。

有几个在列表中查找项的方法。

begin()和end()方法返回迭代器到列表的开头和结尾。

这有利于得到你能够从这个位置通过迭代器的增加或消耗向前或向后移动迭代器。

迭代器通过end()返回并指向在集装箱中越过最后项的项。

末尾的迭代器总是和它所属的列表关联,无论如何是不能废弃的;operator*()不会返回一个适当定义的值。

如果这个列表是empty(),通过begin()返回的迭代器和通过end()返回的迭代器是相等的.

另一个在列表中查找项的方法是使用qFind()法则。

例如:

QValueListlist;

...

QValueList:

:

iteratorit=qFind(list.begin(),list.end(),3);

if(it!

=list.end())

//itpointstothefounditem

它对于在一个列表中同时拥有多种迭代器是安全的。

如果列表中的一些成员是被移除的,指向移除成员的迭代器变为无效的。

插入的列表使任何迭代器都无效。

为了方便,last()方法返回涉及列表中的最后一项,first()返回涉及列表中的第一项。

如果列表是empty(),last()和first()没有明确的行为(你的请求将被损坏或者发生不可预知的事情).小心的使用last()和first(),例如:

QValueListlist;

list.append

(1);

list.append

(2);

list.append(3);

...

if(!

list.empty()){

//OK,modifythefirstitem

int&i=list.first();

i=18;

}

...

QValueListdlist;

doubled=dlist.last();//undefined

因为QValueList是值基础不需要担心在列表中删除项。

如果相应的成员或列表本身被删除,列表保存它自己的副本并可以释放它们。

你可以使用clear()强制列表释放它所有的项.

QValueList是暗中共享的,意思是它能在不同的时间被复制,也就是O

(1).如果多种QValueList实例共享一样的数据,一个需要修改它的内容,这个要修改的实例制作一个副本并修改它的副本;因此它不会影响别的实例;这个带有O(n)时间.这个经常被称为"副本写作".如果一个QValueList正被用于一个多线图的程序,你必须保证能够访问所有的列表。

见QMutex.

有几种向列表中插入项的方法。

prepend()和append()方法分别在列表的开始和结尾插入项。

insert()方法有几个特点并能够用于增加一个项或在列表中的特殊位置增加更多的项。

也有几种方法能够从列表中删除项。

remove()方法有几个不同的变量,能从列表中移除特定的项。

remove()方法能够找到并移除项依照特定项的值。

也能够使用sort()方法给列表分类,或使用QtTemplateLibrary分类.例如使用qHeapSort():

例如:

QValueListlist;

list.append(5);

list.append(8);

list.append(3);

list.append(4);

qHeapSort(list);

另见QValueListIterator,QtTemplateLibraryClasses,ImplicitlyandExplicitlySharedClasses,和Non-GUIClasses.

成员类型文档

QValueList:

:

ConstIterator

这个迭代器是QValueListConstIterator的实例化类型同QValueList.换句话说,如果你实例化QValueList,常量迭代器是一个QValueListConstIterator.几个成员函数使用它,像QValueList:

:

begin(),返回的迭代器指向列表中的第一项。

基本上,这个和迭代器大致上差不多.唯一不同的是你不需为了不常用的操作使用常量迭代器,如果你使用常量迭代器,编辑器能够经常生成较好的代码.

另见QValueListIterator和Iterator.

QValueList:

:

Iterator

这个迭代器是QValueListConstIterator的实例化类型同QValueList.换句话说,如果你实例化QValueList,迭代器是一个QValueListIterator.几个成员函数使用它,像QValueList:

:

begin(),返回的迭代器指向列表中的第一项。

基本上,这个和迭代器大致上差不多.唯一不同的是你不需为了不常用的操作使用常量迭代器,,如果你使用常量迭代器,编辑器能够经常生成较好的代码.

另见QValueListIterator和ConstIterator.

QValueList:

:

const_iterator

列表的常迭代器类型,QValueListConstIterator.

QValueList:

:

const_pointer

T类型的常指针.

QValueList:

:

const_reference

T类型的常参数.

QValueList:

:

iterator

列表的迭代器类型,QValueListIterator.

QValueList:

:

pointer

T类型指针.

QValueList:

:

reference

涉及的T类型.

QValueList:

:

size_type

一个无符号类型,用于描绘不同的大小.

QValueList:

:

value_type

保存在列表中的对象的类型,T.

成员函数文档

QValueList:

:

QValueList()

创建一个空的列表.

QValueList:

:

QValueList(constQValueList&l)

创建l的副本.

这个操作接受O

(1)时间,因为QValueList是暗中共享.

第一次修改列表可获得O(n)时间.

QValueList:

:

QValueList(conststd:

:

list&l)

创建l的副本.

这个构造器可以同STL的集装箱兼容.

QValueList:

:

~QValueList()

销毁列表。

在这个列表中涉及到的值,这个列表中的所有迭代器变为无效的。

注意对于一个迭代器检查它是否有效是很重要的:

QValueList对于性能有很高的调谐,但不适于错误检查。

iteratorQValueList:

:

append(constT&x)

在列表的最后插入x.

另见insert()和prepend().

例如:

checklists/checklists.cpp和fonts/simple-qfont-demo/viewer.cpp.

const_iteratorQValueList:

:

at(size_typei)const

返回一个指向项的迭代器在列表i的位置,或是,如果这个索引在范围之外返回end()。

警告:

这个方法使用线性查找,能够非常慢的扩大列表。

QValueList不能够使随机存取项最优化。

如果你需要随机存取使用一个不同的集装箱,像QValueVector.

iteratorQValueList:

:

at(size_typei)

为了提供方便,这是一个重载成员函数。

它本身的行为像上面的方法。

返回一个指向项的迭代器在列表i的位置,或是,如果这个索引在范围之外返回end()。

referenceQValueList:

:

back()

返回一个最后项的参数.如果不包含最后项(也就是empty()返回TRUE),这个返回值是不确定的.

这个方法支持STL的兼容性.它与last()相等.

另见front().

const_referenceQValueList:

:

back()const

为了提供方便,这是一个重载成员函数。

它本身的行为像上面的方法。

const_iteratorQValueList:

:

begin()const

返回一个指向列表中第一项的迭代器。

如果列表是空的这个迭代器和end()等同

另见first()和end().

例如:

canvas/canvas.cpp,chart/canvasview.cpp,chart/element.cpp,checklists/checklists.cpp,sql/overview/insert/main.cpp,table/statistics/statistics.cpp,和themes/themes.cpp.

iteratorQValueList:

:

begin()

为了提供方便,这是一个重载成员函数。

它本身的行为像上面的方法。

返回一个指向列表中第一项的迭代器。

如果列表是空的这个迭代器和end()等同

另见first()和end().

voidQValueList:

:

clear()

从列表中移除所有项。

另见remove().

size_typeQValueList:

:

contains(constT&x)const

返回在列表中的事件数量的值为x.

size_typeQValueList:

:

count()const

返回列表中的项数量.

另见isEmpty().

例如:

chart/element.cpp和table/statistics/statistics.cpp.

boolQValueList:

:

empty()const

如果列表不包含项则返回TRUE;否则返回FALSE.

另见size().

iteratorQValueList:

:

end()

返回一个指向在列表中过去的最后项的迭代器。

如果列表是空的这个迭代器同begin()等同

另见last()和begin().

例如:

canvas/canvas.cpp,chart/canvasview.cpp,chart/element.cpp,checklists/checklists.cpp,sql/overview/insert/main.cpp,table/statistics/statistics.cpp,和themes/themes.cpp.

const_iteratorQValueList:

:

end()const

为了提供方便,这是一个重载成员函数。

它本身的行为像上面的方法。

返回一个指向在列表中过去的最后项的迭代器。

如果列表是空的这个迭代器同begin()同等.

另见last()和begin().

iteratorQValueList:

:

erase(iteratorit)

从列表中移除被it指向的项.只有it迭代器或其它和it指向相同项的迭代器是无效的。

返回一个it之后项的迭代器,如果没有这样的项返回end()。

这个方法支持STL的兼容性。

它与remove()等同.

iteratorQValueList:

:

erase(iteratorfirst,iteratorlast)

为了提供方便,这是一个重载成员函数。

它本身的行为像上面的方法。

删除从first到last的所有项(不包括last).迭代器是有效的,除非这些都指向删除项的本身。

返回last.

iteratorQValueList:

:

find(constT&x)

返回列表中指向x的第一个事件的迭代器.

没有匹配的项返回end().

const_iteratorQValueList:

:

find(constT&x)const

为了提供方便,这是一个重载成员函数。

它本身的行为像上面的方法。

返回列表中指向x的第一个事件的迭代器.

没有匹配的项返回end().

iteratorQValueList:

:

find(iteratorit,constT&x)

为了提供方便,这是一个重载成员函数。

它本身的行为像上面的方法。

在列表中找到x的第一个事件,把其起始位置赋给it.

如果没有匹配的项返回end().

const_iteratorQValueList:

:

find(const_iteratorit,constT&x)const

为了提供方便,这是一个重载成员函数。

它本身的行为像上面的方法。

在列表中找到x的第一个事件,把其起始位置赋给it.

如果没有匹配的项返回end().

intQValueList:

:

findIndex(constT&x)const

返回第一个事件的索引,其值为x.如果没有匹配的项返回-1.

T&QValueList:

:

first()

返回第一项的参数.如果列表不包含第一项(也就是isEmpty()返回TRUE),这个返

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 表格模板 > 书信模板

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1