2015-12-12 58 views
0

我開發QML應用程式上C++,但目前我套牢了,也許是簡單,錯誤:C++,QT錯誤當分配的QList <T>到的QList <T>

C:\Qt\5.2.1\mingw48_32\include\QtCore\qvector.h:679: error: no match for 'operator==' (operand types are 'ListModel' and 'ListModel') if (!(*--i == *--j)) ^

我的頭是:

#ifndef COMBOBOXUPDATE_H 
#define COMBOBOXUPDATE_H 
#include <QObject> 
#include <QStringList> 
#include <QString> 
#include <QVector> 

struct ListModel; 

class ComboboxUpdate:public QObject 
{ 
Q_OBJECT 
Q_PROPERTY(QVector<ListModel> comboList READ comboList) 

public: 

    ComboboxUpdate(QObject *parent = 0); 
    QVector<ListModel> comboList(); 
    void setComboList(QVector<ListModel> &comboList); 

private: 
QVector<ListModel> m_comboList; 
int   m_count; 
}; 

struct ListModel 
{ 
ListModel(); 
ListModel(QString _text,int _Sqlid) 
{ 
    text=_text; 
    Sqlid=_Sqlid; 
} 
QString text; 
int  Sqlid; 
}; 
#endif // COMBOBOXUPDATE_H 
在此代碼區域中發生

錯誤執行文件中:

void ComboboxUpdate::setComboList( QVector<ListModel> &comboList) 
{ 
    if (m_comboList != comboList) 
    { 
     m_comboList = comboList; 
    } 
} 

I C annot明白爲什麼會出現這個問題。我的主要目標是使用像ListElement這樣的東西從C++端填充組合框。我可以成功填寫QStringList。但我想填寫像ListElement。例如:

ComboBox { 
    model: ListModel { 
       ListElement {sqlid:"1"; text:"Pansi"} 
       ListElement {sqlid:"2"; text:"Rose"} 
       ListElement {sqlid:"3"; text:"Clips"} 
      } 
    anchors.fill: parent 
} 

在QML側這一模型顯示ComboBox文本和值存儲到sqlite的。我怎麼能在C++端做到這一點?

回答

2

您需要爲您的課程ListModel提供operator==。例如:

struct ListModel 
{ 
    bool operator==(const ListModel& other) const { 
     return other.text == text && other.Sqlid == Sqlid; 
    } 
};