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. [solved] problem: Model::data() function never be called.
Qt 6.11 is out! See what's new in the release blog

[solved] problem: Model::data() function never be called.

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

    I created a UI interface based on QWidget by QtDesigner, inside the window, I put labels, buttons and a Tableview. The tablview is referenced by ui->Stepping view, I connect this view to the model I created, ui->SteppingView->setModel(&StepTableModel); the program can bu run. But tableview shows nothing, and the breakpoints I set in the function steptablemodel::data() never be reached. looks like it never call steptablemodel::data() funtion. I do not know what causes the problem. thanks for help.

    **** update: thanks for Lykurg's help.

    @
    RemoteContol::RemoteContol(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::RemoteContol)
    {
    QStringList a;
    ui->setupUi(this);

    connect(ui->UpdateButton,SIGNAL(clicked()),this,SLOT(sendSettingParameters()));
    udpSocket.bind(QHostAddress("10.10.10.11"),49166);
    connect(&udpSocket, SIGNAL(readyRead()), this, SLOT(processPendingData()));
    connect(ui->GPSradioButton, SIGNAL(toggled(bool)), this, SLOT(baseTimeToggled()));
    connect(ui->ManualradioButton, SIGNAL(toggled(bool)), this, SLOT(opModeToggled()));
    connect(ui->FDradioButton, SIGNAL(clicked()), this, SLOT(waveformToggled()));
    connect(ui->TD50radioButton, SIGNAL(clicked()), this, SLOT(waveformToggled()));
    connect(ui->TD33radioButton, SIGNAL(clicked()), this, SLOT(waveformToggled()));
    connect(ui->TD25radioButton, SIGNAL(clicked()), this, SLOT(waveformToggled()));
    connect(ui->FreqSetcomboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(freqprodChanged(int)));
    CurrentDateTime= QDateTime::fromString("20000101","yyyyMMdd");
    ui->DatetimeLCD->display("2000-01-01  00:00:00");
    oldtimeflag=0;
    baseTime = 0;
    opMode = 0;
    waveform = 0;
    a<<"aaa"<<"bbb"<<"ccc";
    a<<"1aa"<<"b2b"<<"cc3";
    steptablemodel StepTableModel(a);
    ui->SteppingView->setModel(&StepTableModel);
    ui->SteppingView->show();
    

    }

    class steptablemodel : public QAbstractTableModel
    {
    Q_OBJECT
    public:
    explicit steptablemodel(QObject *parent = 0);
    steptablemodel(QStringList &tablelist, QObject *parent = 0);
    int rowCount(const QModelIndex &parent) const;
    int columnCount(const QModelIndex &parent) const;
    QVariant data(const QModelIndex &index, int role) const;

    signals:

    public slots:

    private:
    QStringList stepTable;
    }

    QVariant steptablemodel::data(const QModelIndex &index, int role) const
    {
    if (!index.isValid()) return QVariant();

    if(index.row() >= stepTable.size() || index.row() < 0)
        return QVariant();
    
    if (role == Qt::DisplayRole) {
        return stepTable.at(index.row()*columnCount(index)+index.column());
    }
    return QVariant();
    

    }@

    1 Reply Last reply
    0
    • L Offline
      L Offline
      Lykurg
      wrote on last edited by
      #2

      Yout have to create the model on the heap, otherwise it gets out of scope at the constructors end (that means it is deleted...)

      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