E
E
Evgeny Petryaev2021-05-01 15:39:18
Qt
Evgeny Petryaev, 2021-05-01 15:39:18

Problem with characters in qtablewidget?

I fill in the table with 3 meanings, ra3 from ra3y part of the English words is entered, and now it’s like in the picture

#pragma once

#include <ctime>
#include <cstring>
#pragma warning(disable : 4996)
class Task
{
public:
  int id;
  char* task;
  int parentTask;
  char* executor;
  int idExecutor;
  tm* dateStart;
  tm* dateDeathLine;
  char* status;
  char* oldtask;
  Task();
  void AddTask(char* task_, int parentTask_, char* executor_,
    int idExecutor_, tm* dateDeathLine_);
  void DeleteTask(int num);
  ~Task();
};
#include "Task.h"

Task::Task()
{
  task = new char[1024];
  executor = new char[256];
  status = new char[64];
  oldtask = new char[2048];
  dateDeathLine = new tm();
  dateStart = new tm();
};


vector<vector<string>> v;
    vector<string> tmp;
    char* date_string = new char[50];
    for (int i = 0; i < db.vTask.size(); i++)
    {
        tmp.push_back(to_string(db.vTask[i].id));
        tmp.push_back(db.vTask[i].task);
        tmp.push_back(to_string(db.vTask[i].parentTask));
        tmp.push_back(db.vTask[i].executor);
        strftime(date_string, 50, " %Y-%m-%d", db.vTask[i].dateDeathLine);
        tmp.push_back(date_string);
        strftime(date_string, 50, "%Y-%m-%d", db.vTask[i].dateStart);
        tmp.push_back(date_string);
        tmp.push_back(db.vTask[i].status);
        tmp.push_back(db.vTask[i].oldtask);
        v.push_back(tmp);
        tmp.clear();
    }
    for(int i=0;i<db.numRow;i++)
        for (int j = 0; j < db.numCol; j++)
        {
            qstr = QString::fromStdString(v[i][j]);
            table.setItem(i, j, new QTableWidgetItem(qstr));
        
        }

608d4bf44cd29439194375.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Petryaev, 2021-05-01
@Gremlin92

Tupanul had to copy strings, not assign

Task* task_ = new Task();
    for (int i = 0; i < nrows; i++)
    {
        task_->id = atoi(PQgetvalue(res, i, 0));
        strcpy(task_->task , PQgetvalue(res, i, 1));
        task_->parentTask = atoi(PQgetvalue(res, i, 2));
        strcpy(task_->executor , PQgetvalue(res, i, 3));
        char* ddl = PQgetvalue(res, i, 4);
        ddl[4] = ddl[7] = '\0';
        task_->dateDeathLine->tm_year = atoi(&ddl[0]) - 1900;
        task_->dateDeathLine->tm_mon = atoi(&ddl[5]) - 1;
        task_->dateDeathLine->tm_mday = atoi(&ddl[8]);
        ddl = PQgetvalue(res, i, 5);
        ddl[4] = ddl[7] = '\0';
        task_->dateStart->tm_year = atoi(&ddl[0]) - 1900;
        task_->dateStart->tm_mon = atoi(&ddl[5]) - 1;
        task_->dateStart->tm_mday = atoi(&ddl[8]);
        strcpy(task_->status , PQgetvalue(res, i, 6));

        strcpy(task_->oldtask , PQgetvalue(res, i, 7));
        cout << " Id: " << task_->id;
        cout << " Task: " << task_->task;
        cout << " Parent: " << task_->parentTask;
        cout << " Executor: " << task_->executor;

        char* date_string = new char[50];
        strftime(date_string, 50, " %Y-%m-%d", task_->dateDeathLine);
        cout << " DeathLine: " << date_string;

        strftime(date_string, 50, "%Y-%m-%d", task_->dateStart);
        cout << " Start: " << date_string;
        cout << " Status: " << task_->status;
        cout << " Oldtask: " << task_->oldtask << endl;
        vTask.push_back(task_);
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question