Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何通过qqmlistproperty显示数据库中的记录_C++_Qt_Qqmllistproperty - Fatal编程技术网

C++ 如何通过qqmlistproperty显示数据库中的记录

C++ 如何通过qqmlistproperty显示数据库中的记录,c++,qt,qqmllistproperty,C++,Qt,Qqmllistproperty,使用qqmlistproperty通过listview显示数据库中的记录 我试图通过qqmlistproperty显示数据库中的记录,但它只显示最后的记录 DataManager::DataManager(QObject *parent) : QObject(parent) { } QQmlListProperty<EmployeeDetails> DataManager::employeedetailslist() { return QQmlListProperty<

使用qqmlistproperty通过listview显示数据库中的记录

我试图通过qqmlistproperty显示数据库中的记录,但它只显示最后的记录

DataManager::DataManager(QObject *parent) : QObject(parent)
{

}
QQmlListProperty<EmployeeDetails> DataManager::employeedetailslist()
{
    return QQmlListProperty<EmployeeDetails>(this, m_employeeDetailsList);
}

void DataManager::setEmployeeDetailsList(const QList<EmployeeDetails *> &employeeDetailsList)
{
    m_employeeDetailsList = employeeDetailsList;
}

void DataManager::printAllPersons(){
    m_employeeDetailsList.clear();
    EmployeeDetails *em = new EmployeeDetails();
    QSqlQuery query("SELECT * FROM employee");
    int idName = query.record().indexOf("name");
    while (query.next())
    {
       em->setName( query.value(idName).toString());
       m_employeeDetailsList.append(em);

    }
    int count  = m_employeeDetailsList.count();
    for (int i =0;i<count;i++) {
        qDebug()<<"name"<<m_employeeDetailsList[i];

    }
    qDebug() <<"count"<<count;
//    qDebug() <<"name"<<m_employeeDetailsList.;
    emit listchanged();


}
DataManager::DataManager(QObject*parent):QObject(parent)
{
}
QQmlListProperty数据管理器::employeedetailslist()
{
返回qqmlistproperty(这是m_EmployeeDetailList);
}
void数据管理器::setEmployeeDetailsList(常量QList和employeeDetailsList)
{
m_employeeDetailsList=employeeDetailsList;
}
void DataManager::printallperson(){
m_employeeDetailsList.clear();
EmployeeDetails*em=新的EmployeeDetails();
QSqlQuery查询(“从员工中选择*);
int idName=query.record().indexOf(“名称”);
while(query.next())
{
em->setName(query.value(idName.toString());
m_employeeDetailsList.append(em);
}
int count=m_employeeDetailsList.count();
对于(int i=0;i