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. How to output the data from tablemodel?
Forum Updated to NodeBB v4.3 + New Features

How to output the data from tablemodel?

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 984 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.
  • S Offline
    S Offline
    shalongbasi
    wrote on last edited by
    #1

    In the function sendSettingParameters(void) of class RemoteControl, I want to get all the data from QList<QList<QVariant> > stepTable in the class steptablemodel output to QDataStream "out" so that it can be send out through UDP socket. The way I tried with function stepTable2Stream() is not working. I tried to overload << for class steptablemode, but it cannot access stepTable from the overload function <<. How can I do it? Thanks. The data inside QList<QList<QVariant> > stepTable are int or float

    @class RemoteContol : public QWidget
    {
    Q_OBJECT

    public:
    explicit RemoteContol(QWidget *parent = 0);
    ~RemoteContol();

    private:
    Ui::RemoteContol *ui;

    QUdpSocket udpSocket;
    quint8 baseTime;    // 0:GPS 1: UTC
    quint8 opMode;      // 0:Manual 1:Auto
    quint8 waveform;    // 0:FD 1:TD50 2:TD33 3:TD25
    steptablemodel StepTableModel;
    

    };
    class steptablemodel : public QAbstractTableModel
    {
    Q_OBJECT
    public:
    explicit steptablemodel(QObject *parent = 0);
    void setStepTable(QList<QList<QVariant> > &tablelist);
    friend QDataStream& operator <<(QDataStream& out, const steptablemodel& steptable);
    QDataStream stepTable2Stream();
    signals:

    public slots:
    void insertAStep(QList<QVariant> step, const QModelIndex &index);
    private:
    QList<QList<QVariant> > stepTable;
    };

    void RemoteContol::sendSettingParameters(void)
    {
    float a=2.3;
    QByteArray datagram;
    QDataStream out(&datagram,QIODevice::WriteOnly);
    out.setVersion(QDataStream::Qt_4_6);
    out.setByteOrder(QDataStream::LittleEndian);
    out.setFloatingPointPrecision(QDataStream::SinglePrecision);
    out << baseTime;
    if (opMode==0) { //manual mode
    out << opMode;
    if (ui->FreqSetcomboBox->currentIndex()==0)
    out << (float)ui->FREQSetBox->value();
    else
    out << 1/(float)ui->FREQSetBox->value();
    out << (float) ui->CurrentSetBox->value()
    << (quint8) 0 << waveform
    << (quint16) ui->VoltageSetBox->value()
    << (quint8) ui->PowerspinBox->value();
    } else { // auto stepping table mode
    out = StepTableModel.stepTable2Stream(); <---- here causes the problem
    }
    udpSocket.writeDatagram(datagram,QHostAddress("10.10.10.255"),49166);
    }

    QDataStream steptablemodel::stepTable2Stream()
    {
    QDataStream stream;
    stream << stepTable.size();
    for (int i=0; i<stepTable.size(); i++) {
    stream <<stepTable[i][0].toFloat()<<stepTable[i][1].toFloat()
    <<stepTable[i][2].toInt();
    if (stepTable[i][3].toString().compare("FD")==0)
    stream << (quint8) 0;
    else if (stepTable[i][3].toString().compare("TD50")==0)
    stream << (quint8) 1;
    else if (stepTable[i][3].toString().compare("TD33")==0)
    stream << (quint8) 2;
    else if (stepTable[i][3].toString().compare("TD25")==0)
    stream << (quint8) 3;
    stream <<stepTable[i][4].toInt()<<stepTable[i][5].toInt();
    }
    return stream;
    }
    @

    1 Reply Last reply
    0
    • M Offline
      M Offline
      Mario84
      wrote on last edited by
      #2

      I guess your problem is that the QDataStream (as the name already says) is a stream, which means it does not store the data itself, it is just a class used for serialization into a QIODevice.
      So you should either use the stream to write to such a device inside stepTable2Stream() or return your data as something like a QByteArray and put that into a stream outside...

      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