CListView二行数据python删除一行数据第一行失败?python删除一行数据第二行内存错误?//什么原因?

5797人阅读
qt 移动开发(10)
//删除数据库中的选中行
QItemSelectionModel *selections = ui-&tableView-&selectionModel();
QModelIndexList selected = selections-&selectedIndexes();
QMap&int, int&
foreach (QModelIndex index, selected)
rows.insert(index.row(), <span style="color:#);
QMapIterator&int, int& r(rows);
r.toBack();
while (r.hasPrevious()) {
r.previous();
model-&removeRow(r.key());
//得到id 并删除数据库数据
int curRow = ui-&tableView-&currentIndex().row();
QModelIndex index = ui-&tableView-&currentIndex();
int id=index.sibling(curRow,<span style="color:#).data().toInt(); //删除数据库中数据 QSqlQuery
query.prepare(&delete from table where id =:id &);
query.bindValue(&id&,id);
query.exec();
if(!query.isActive()){
QMessageBox::critical(this,QString::fromLocal8Bit(&提示&),QString::fromLocal8Bit(&删除数据失败!&));
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:433664次
积分:4561
积分:4561
排名:第6379名
原创:94篇
转载:78篇
评论:31条
(1)(2)(3)(1)(1)(1)(1)(1)(3)(4)(3)(11)(3)(5)(13)(3)(14)(9)(17)(2)(12)(26)(7)(12)(1)(1)(4)(1)(2)(2)(4)(1)(1)HRESULT bResult = S_OK;
int iItemI
CListCtrl & ListCtrl = GetListCtrl();
iItemIndex = ListCtrl.GetSelectionMark();
if(bResult==ListCtrl.DeleteItem(iItemIndex))
...................
------解决方案--------------------
HRESULT bResult = S_OK;int iItemI& CListCtrl & ListCtrl = GetListCtrl();iItemIndex = ListCtrl.GetSelectionMark();if (iItemIndex == -1){
pmyListCtrl-&SetSelectionMark(0);
iItemIndex = 0;}if(bResult==ListCtrl.DeleteItem(iItemIndex)){
...................}
12345678910
12345678910
12345678910 上一篇:下一篇:文章评论相关解决方案 12345678910 Copyright & &&版权所有9278人阅读
转载---MFC(50)
#include &afxtempl.h&
Construction
Constructs an empty ordered list.
建立一个链表
CList&int,int& myL//建立一个int链表
CList&CString,CString&& myList(16);//建立一个cstring的链表,后面的16表示链表里面数据的个数,如果不写的话,可能是不限个数?
CList&MYTYPE,MYTYPE&& myL//建立一个MYTYPE类型(自定义)的链表
如果不存入数据的话,刚建立的链表是空的,头尾都为空
Head/Tail Access
Returns the head element of the list (cannot be empty).
返回链表的头数据
CList&int,int& myL
for(int i=0;i&10000;i&#43;&#43;) { myList.AddTail(int(i)); }//存入数据
int tmp=myList.GetHead();//tmp被赋予了0
Returns the tail element of the list (cannot be empty).
返回链表的尾数据
CList&int,int& myL
for(int i=0;i&10000;i&#43;&#43;) { myList.AddTail(int(i)); }//存入数据
int tmp=myList.GetTail();//tmp被赋予了9999
Operations
Removes the element from the head of the list.
移除链表头数据,链表数据个数减1,返回缩减前的头数据
CList&int,int& myL
for(int i=0;i&10000;i&#43;&#43;) { myList.AddTail(int(i)); }//存入数据
int tmp=myList.RemoveHead();//tmp被赋予了之前的头数据:0;同时数据个数变为9999;
Removes the element from the tail of the list.
移除链表尾数据,链表数据个数减1,返回缩减前的尾数据
CList&int,int& myL
for(int i=0;i&10000;i&#43;&#43;) { myList.AddTail(int(i)); }//存入数据
int tmp=myList.RemoveTail();//tmp被赋予了之前的尾数据:9999;同时数据个数变为9999;
Adds an element (or all the elements in another list) to the head of the list (makes a new head).
在链表头处插入新数据,链表数据个数加1,返回新的链表头位置(POSITION);
CList&int,int& myL
for(int i=0;i&10000;i&#43;&#43;) { myList.AddTail(int(i)); }//存入数据
POSITION pos=myList.AddHead(int(314));//链表有了一个新的头数据:314;同时链表个数变为10001;pos为新的头的位置;
Adds an element (or all the elements in another list) to the tail of the list (makes a new tail).
在链表尾处插入新数据,链表数据个数加1,返回新的链表尾位置(POSITION);
CList&int,int& myL
for(int i=0;i&10000;i&#43;&#43;) { myList.AddTail(int(i)); }//存入数据
POSITION pos=myList.AddTail(int(314));//链表有了一个新的尾数据:314;同时链表个数变为10001;pos为新的尾的位置;
Removes all the elements from this list.
清空链表,其头尾皆变成空指针;
Returns the position of the head element of the list.
返回链表头的位置;
CList&int,int& myL
for(int i=0;i&10000;i&#43;&#43;) { myList.AddTail(int(i)); }//存入数据
POSITION pos=myList.GetHeadPosition();//获得链表头的位置
Returns the position of the tail element of the list.
返回链表尾的位置;
CList&int,int& myL
for(int i=0;i&10000;i&#43;&#43;) { myList.AddTail(int(i)); }//存入数据
POSITION pos=myList.GetTailPosition();//获得链表尾的位置
Gets the next element for iterating.
返回当前位置的数据,之后,位置后移一位;
CList&int,int& myL
for(int i=0;i&10000;i&#43;&#43;) { myList.AddTail(int(i)); }//存入数据
POSITION pos=myList.GetHeadPosition();//获得链表头的位置
int tmp=myList.GetNext(pos);//tmp被赋予了头数据的&#20540;:0;同时pos指向第二个数据1;
Gets the previous element for iterating.
返回当前位置的数据,之后,位置前移一位;
CList&int,int& myL
for(int i=0;i&10000;i&#43;&#43;) { myList.AddTail(int(i)); }//存入数据
POSITION pos=myList.GetTailPosition();//获得链表尾的位置
int tmp=myList.GetNext(pos);//tmp被赋予了尾巴数据的&#20540;:9999;同时pos指向倒数第二个数据9998;
Retrieval/Modification
Gets the element at a given position.
返回指定位置的数据;
CList&int,int& myL
for(int i=0;i&10000;i&#43;&#43;) { myList.AddTail(int(i)); }//存入数据
POSITION pos=myList.GetTailPosition();//获得链表尾的位置,还可以继续改变pos,以指向其他数据
int tmp=myList.GetAt(pos);//tmp被赋予链表尾的数据
Sets the element at a given position.
CList&int,int& myL
for(int i=0;i&10000;i&#43;&#43;) { myList.AddTail(int(i)); }//存入数据
POSITION pos=myList.GetTailPosition();//获得链表尾的位置,还可以继续改变pos,以指向其他数据
myList.SetAt(pos,int(222));//将链表尾部的数据赋成222
Removes an element from this list, specified by position.
清除指定位置处的数据;同时数据个数减1;
CList&int,int& myL
for(int i=0;i&10000;i&#43;&#43;) { myList.AddTail(int(i)); }//存入数据
POSITION pos=myList.GetTailPosition();//获得链表尾的位置
myList.RemoveAt(pos);//链表pos(尾部)位置的数据被清除,数据个数变为9999;
Inserts a new element before a given position.
在指定位置前插入一个新数据,数据个数加1;
CList&int,int& myL
for(int i=0;i&10000;i&#43;&#43;) { myList.AddTail(int(i)); }//存入数据
POSITION pos=myList.GetHeadPosition();//获得第一个数据的位置
myList.InsertBefore(pos,int(123));//在第一个数据前插入一个新数据: 123,同时数据个数变为10001
Inserts a new element after a given position.
在指定位置后插入一个新数据,数据个数加1;
CList&int,int& myL
for(int i=0;i&10000;i&#43;&#43;) { myList.AddTail(int(i)); }//存入数据
POSITION pos=myList.GetHeadPosition();//获得第一个数据的位置
myList.InsertAfter(pos,int(123));//在第一个数据后插入一个新数据: 123,同时数据个数变为10001
Gets the position of an element specified by pointer value.
返回指定数据对应的位置;
CList&int,int& myL
for(int i=0;i&10000;i&#43;&#43;) { myList.AddTail(int(i)); }//存入数据
POSITION pos=myList.Find(int(0));//获得0(链表头)的位置
Gets the position of an element specified by a zero-based index.
返回索引号对应的位置;
POSITION pos=myList.FindIndex(0);//0表示链表头,以此类推
Returns the number of elements in this list.
返回链表的数据个数
int num=myList.GetCount();//获得链表的数据个数
Tests for the empty list condition (no elements).
判定链表是否为空;
返回1表示链表是空,返回0表示链表非空;
BOOL empty=myList.IsEmpty();
为什么CList&int,int&后一个参数不定义为引用 ,而CList&CString,CString&& 要定义为引用呢,
为什么要这样用,什么时候该用引用,后一个参数的具体意思又是什么,期待详细解答
谢谢~~ 引用实质就是地址,在32位的系统中,一个地址和一个int所占用的字节数是一样的,所以CList&int,int&和CList&CString,CString&&都是正确的。&& 引用可省空间,少复制,但int空间太小,故可不用
CList&TYPE, ARG_TYPE& 后一个参数是ARG_TYPE
自己的例子:
一个遍历并进行赋&#20540;的 例子:
POSITION hpos = pView-&m_pList-&GetHeadPosition();
for( i=0;i&pView-&m_pList-&GetCount();i++)
if((pView-&m_pList-&GetAt(hpos)).value==pView-&m_nSelect)
item=pView-&m_pList-&GetAt(hpos);
item.invalidateInfo=1;
item.bHasChecked=TRUE; // 已审核
item.bHasModified=FALSE;// 未修改
pView-&m_pList-&SetAt(hpos,item);
pView-&m_pList-&GetNext(hpos);
&&&&&&& 此前,我们已经知道了POSITION,其实就是一个类&#20284;于学号的指针,我们也知道了CArray的效率将会随着元素数目的变化,而不断恶化。现在,&#20284;乎已经到了不得不讲讲CList的时候了。
CList与CArray,虽然他们的内部数据结构截然不同,但是MFC为我们提供的接口函数,还是比较相&#20284;的。在使用CList之前,我们必须要知道,它是以双向链表的形式存在的。
&&&&&&& 对于链表来说,一些常用的操作无非就是:创建,追加(从头,或者从尾), 删除,插入以及检索而已。同样,CList其实也就是封装了这些东西。下面,我们看一个简短的例子,不过它并没有囊括所有的成员函数的用法。
class Point
Point(int x, int y)
bool operator==(const Point& src) const
return ( (m_x == src.m_x) && (m_y == src.m_y) );
typedef CList&Point, Point&&
int main()
point, elem1, elem2;
elem1.m_x = 52;
elem1.m_y = 102;
elem2.m_x = 14;
elem2.m_y = 1621;
// add a element from tail, certainly, also can from head
lst.AddTail(elem1);
lst.AddTail(elem2);
// print the point count
cout&&&count: &&&lst.GetCount()&&
// traverse the whole list
size_t index = 0;
for( POSITION ps = lst.GetHeadPosition();lst.GetNext(ps) )
// extract the point according the current position
point = lst.GetAt(ps);
printf(&index: %d, m_x = %d, m_y = %d\n&, index++, point.m_x, point.m_y);
// search the point which is equal to elem1
ps = lst.Find(elem1);
point = lst.GetAt(ps);
printf(&elem1: m_x = %d, m_y = %d\n&, point.m_x, point.m_y);
Point elem3(123, 123123);
// insert elem3 into the list after elem1
lst.InsertAfter(ps, elem3);
// remove elem1
lst.RemoveAt(ps);
// remove all the rest
lst.RemoveAll();
&&&&&&&& 这个例子,我基本上,都给出了注释,唯一需要着重提醒大家的是:Find这个函数,因为在Find的源码里,需要我们提供一个判等的运算符重载,当然,我已经在Point类中,实现了,如果哪天你遇到了error C2678: binary '==' : no operator defined which takes a left-hand operand of type 'const class Point' (or there is no acceptable conversion)这样一个编译错误的话,那么你将不得不自己动手为我们这个不懂事的类,添加一个判等操作。
&&&&&&& 前面,我们讲过有关CArray会在元素大量堆积的时候,出现效率瓶颈,并且也告诉大家CList&#20284;乎可以替代这么一个东东。其实,并非是CList替换了CArray,而是链式数据结构替代了线性的数组。在链表的一端进行操作,无疑是非常方便高效的,所以我们的确需要用CList替换彼时的CArray
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:2082968次
积分:23738
积分:23738
排名:第269名
原创:415篇
转载:245篇
译文:39篇
评论:261条
(4)(7)(9)(3)(2)(2)(4)(7)(1)(3)(5)(2)(5)(11)(2)(1)(3)(3)(9)(5)(23)(5)(2)(1)(4)(2)(10)(21)(1)(19)(1)(6)(2)(2)(3)(6)(4)(5)(14)(14)(7)(11)(13)(16)(11)(25)(13)(12)(12)(2)(13)(9)(15)(25)(16)(24)(1)(3)(4)(7)(1)(8)(44)(18)(25)(21)(9)(2)(4)(6)(3)(35)(24)(3)(2)(1)(2)(5)(11)(3)

我要回帖

更多关于 python删除一行数据 的文章

 

随机推荐