poulh / qjsontablemodel

QT Table Model that takes arrays of hashes in JSON format to populate the table
26 stars 4 forks source link

Error when initialize a new QJsonTableModel object #2

Open yusup209 opened 4 years ago

yusup209 commented 4 years ago

Hi. When i initialize new QJsonTableModel, i got an error says error: undefined reference toQJsonTableModel::QJsonTableModel(QVector<QMap<QString, QString> > const&, QObject*)`

Here is the code.

` void MainWindow::LoadDataFromJson(){ QNetworkAccessManager *man = new QNetworkAccessManager(this);

QNetworkRequest request;
connect(man, &QNetworkAccessManager::finished,this,&MainWindow::LoadDataFromJsonResponse);
request = QNetworkRequest(QUrl("http://localhost:3030/get_groups"));
man->get(request);
qDebug() << "sending get request...";

} void MainWindow::LoadDataFromJsonResponse(QNetworkReply* repl){ qDebug() << "getting response..."; QString response = repl->readAll(); QJsonDocument doc = QJsonDocument::fromJson(response.toUtf8()); QJsonObject obj = doc.object();

bool keySucc = obj["success"].toBool();
QString keyMsg = obj["message"].toString();
QJsonArray dataResponse = obj["data"].toArray();

qDebug() << "response received.";
qDebug() << dataResponse[0];

QJsonTableModel::Header tblHeader;
tblHeader.push_back( QJsonTableModel::Heading( { {"title","Id"},    {"index","id"} }) );
tblHeader.push_back( QJsonTableModel::Heading( { {"title","Name"},    {"index","name"} }) );
tblHeader.push_back( QJsonTableModel::Heading( { {"title","Description"},    {"index","description"} }) );
tblHeader.push_back( QJsonTableModel::Heading( { {"title","CreatedAt"},    {"index","created_at"} }) );
tblHeader.push_back( QJsonTableModel::Heading( { {"title","UpdatedAt"},    {"index","updated_at"} }) );

tblModel = new QJsonTableModel(tblHeader, this);
ui->tableView->setModel(tblModel);
tblModel->setJson(doc);

} `

here is the code screenshot : https://imgur.com/M0JLlwe the json : https://imgur.com/a/mL9RmLN

Thank you.

agulamkadirov commented 3 years ago

Aw, I've been late :( but anyway...

You should add path of qjsontablemodel.cpp to your project(int .pro file), like that:

SOURCES += \
    main.cpp \
    mainwindow.cpp \
    D:/Qt/Qt5.12.10/5.12.10/mingw73_32/include/QtCore/qjsontablemodel.cpp

and you will be able to include qjsontablemodel.h to your project Hope it helps