Hey guys,
From the code I’ll be showing, that I’m basically trying to do is read some JSON data from two places and add it to a QTableView.
I managed to read everything OK, but when I try to add info to the QTableView it doesn’t work. No error, yet no visual output.
Can anyone please take a look and tell me what I’m doing wrong? It’s been 2 days already and I’m starting to lose patience.
Please do not commend upon the quality of the code, since I haven’t write C++ code since 10 years ago.
OrderTableView.h
#ifndef OrderWidget_H
#define OrderWidget_H
#include <QTableView>
#include <QItemSelection>
#include <QSortFilterProxyModel>
#include "ordertablemodel.h"
#include "orderthread.h"
#include "qjson/src/parser.h"
class OrderTableView : public QTableView
{
Q_OBJECT
public:
explicit OrderTableView(QWidget *parent = 0);
~OrderTableView();
private:
OrderTableModel *table;
QSortFilterProxyModel *proxyModel;
OrderThread *orderThread;
QNetworkAccessManager networkManager;
// void parseNewDataFromSite(QByteArray json);
// void updateOrdersList(QVariantList list);
QVariantList readCurrentOrders();
void writeCurrentOrders(QVariantList list);
signals:
void selectionChanged (const QItemSelection &selected);
public slots:
void readOrders();
void ordersRead(QNetworkReply *networkReply);
};
#endif // OrderWidget_H
OrderTableView.cpp
http://pastebin.com/K8W9cTAX
OrderTableModel.h
#ifndef PRINTDATAMODEL_H
#define PRINTDATAMODEL_H
#include <QAbstractTableModel>
#include <QVariant>
#include <QDebug>
class OrderTableModel : public QAbstractTableModel
{
Q_OBJECT
public:
QVariantList orders;
explicit OrderTableModel(QObject *parent = 0);
int rowCount(const QModelIndex &parent = QModelIndex()) const ;
int columnCount(const QModelIndex &parent = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
bool wasPrinted(QVariantMap order);
void markAsPrinted(QVariantMap *order);
bool orderKeyExists(QVariantMap order, QString key);
QString orderKeyValue(QVariantMap order, QString key);
void addOrder(QVariantMap order);
void addOrder();
private:
signals:
public slots:
};
#endif // PRINTDATAMODEL_H
OrderTableModel.cpp
http://pastebin.com/Zd8qfspa
MainWindow.cpp
#include "mainwindow.h"
#include "ordertablemodel.h"
#include <QTableView>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent)
{
setWindowTitle(QString("Partnermed Printer"));
widget = new OrderTableView(this);
setCentralWidget(widget);
}
MainWindow::~MainWindow()
{
delete widget;
}
↧