Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTableView not showing items
Qt 6.11 is out! See what's new in the release blog

QTableView not showing items

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 1.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gridorian
    wrote on last edited by
    #1

    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;
    }@

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved