E
E
Evgeny Petryaev2021-05-01 17:56:26
Qt
Evgeny Petryaev, 2021-05-01 17:56:26

Why is this code not compiling?

MyWidget.h

#pragma once

#include <QtWidgets/qwidget.h>
#include <QtWidgets/qtablewidget.h>
#include "DatabaseConnection.h"

#pragma comment(lib,"Qt5Core.lib")
#pragma comment(lib,"Qt5Widgets.lib")
class MyWidget
{
public:
  DatabaseConnection db;
  void InitWidget();
  void Tape(QTableWidget table,bool t);
};

MyWidget.cpp
#include "MyWidget.h"
void MyWidget::InitWidget()
{
    QTableWidget tableworkers;
    QTableWidget tabletasks;
    db.Connect();
    db.Query();
    QWidget self;
    self.setWindowTitle("Task system");
    self.setGeometry(0, 0, 1000, 700);

    db.StandartQuery();
   // QTableWidget tableworkers;
    tableworkers.setParent(&self);
    tableworkers.setColumnCount(db.numCol);
    tableworkers.setRowCount(db.numRow);
    tableworkers.setGeometry(0, 0, 950, 300);
    Tape(tableworkers,false);
    db.Query();
    //QTableWidget table;
    tabletasks.setParent(&self);
    tabletasks.setColumnCount(db.numCol);
    tabletasks.setRowCount(db.numRow);
    tabletasks.setGeometry(0, 300, 950, 300);
    Tape(tabletasks, true);
    
    self.show();
}

void MyWidget::Tape(QTableWidget table,bool t)
{
    QStringList list;
    QString qstr;
    for (int i = 0; i < db.namescol.size(); i++)
    {
        qstr = QString::fromStdString(db.namescol[i]);
        list.push_back(qstr);
    }
    table.setHorizontalHeaderLabels(list);
    vector<vector<string>> v;
    vector<string> tmp;
    if (t)
    {
        char* date_d = new char[50], * date_s = new char[50], * strid = new char[50], * strptask = new char[50];
        for (int i = 0; i < db.vTask.size(); i++)
        {
            itoa(db.vTask[i]->id, strid, 10);
            tmp.push_back(strid);
            tmp.push_back(db.vTask[i]->task);
            itoa(db.vTask[i]->parentTask, strptask, 10);
            tmp.push_back(strptask);
            tmp.push_back(db.vTask[i]->executor);
            strftime(date_d, 50, " %Y-%m-%d", db.vTask[i]->dateDeathLine);
            tmp.push_back(date_d);
            strftime(date_s, 50, "%Y-%m-%d", db.vTask[i]->dateStart);
            tmp.push_back(date_s);
            tmp.push_back(db.vTask[i]->status);
            tmp.push_back(db.vTask[i]->oldtask);
            v.push_back(tmp);
            tmp.clear();
        }
    }
    else
    {
        char*strid = new char[50];
        for (int i = 0; i < db.vWorker.size(); i++)
        {
            itoa(db.vWorker[i]->id, strid, 10);
            tmp.push_back(strid);
            tmp.push_back(db.vWorker[i]->name);
            tmp.push_back(db.vWorker[i]->position);
            v.push_back(tmp);
            tmp.clear();
        }
    }
    for (int i = 0; i < v.size(); i++)
        for (int j = 0; j < v[i].size(); j++)
        {
            qstr = QString::fromStdString(v[i][j]);
            table.setItem(i, j, new QTableWidgetItem(qstr));
        }
}

main.cpp
#include <iostream>
#include <QtWidgets/QApplication>
#include "MyWidget.h"
using namespace std;
int main(int argc, char* argv[])
{
    QApplication a(argc, argv);
    MyWidget mw;
    mw.InitWidget();
    return a.exec();
}

Throws an error on two lines with Tape, an attempt was made to refer to a remote function
608d6dcc55ab0246272240.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Pavlov, 2021-05-01
@Stalker31

The qtablewiget.h file is not available
. Check included file paths

W
Wataru, 2021-05-01
@wataru

The QTableWidget class has a remote copy constructor. It cannot be copied.
You are passing QTableWidged tableworkers to the function by value. The compiler tries to copy the value and runs into this error.
Pass by reference or as a pointer to your Tape function. Well, or through std::move() when called, if the class has a move constructor.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question