Answer the question
In order to leave comments, you need to log in
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);
};
#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));
}
}
#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();
}
Answer the question
In order to leave comments, you need to log in
The qtablewiget.h file is not available
. Check included file paths
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 questionAsk a Question
731 491 924 answers to any question