Pieces of the program, I will give a part, because it is very large and secret)
How to fix crash on the 6th line of code?
Hierarchy of connected header files: DataXY is connected to the IOController, and it to the MainWindow, and it to the Main
Kusman method from IOController:
IOController.cpp:
{//какой-то метод... this->writeToBufferWin(answer);//В этой строке стало вылетать из-за кода 3 строками ниже srand(time(0)); this->openUrl(this->linkJob); this->randomSleep(1,2); DataXY *dataScreen = new DataXY(this->searchButtonRunTask());//Вылет тут //Если ее закоменнтить, вылетать не будет, но эта строка крайне важна cout << "X: " << dataScreen->leftLowerBound.x <<endl; } DataXY IOController::searchButtonRunTask() {//Создаю что статически, что динамически - вылетает QPixmap screenButton; DataXY *dataScreenXY = new DataXY(screenButton); dataScreenXY->searchButtonRunTask(); return *dataScreenXY; //ТУТ ВЫЛЕТАЕТ ПОЧЕМУ-ТО } bool IOController::writeToBufferWin(string str) { // QClipboard *clipB = QGuiApplication::clipboard(); // clipB->clear(); // clipB->setText(QString::fromStdString(str)); //Если это расскоментировать и закомментировать то что ниже до ретерна, станет вылетать строка clipB->setText(QString::fromStdString(str)); OpenClipboard(nullptr); EmptyClipboard(); HGLOBAL hgBuffer; char* chBuffer; hgBuffer = GlobalAlloc(GMEM_MOVEABLE,(sizeof(str) * str.size()) + 1); chBuffer= (char*)GlobalLock(hgBuffer); strcpy(chBuffer, LPCSTR(str.c_str())); GlobalUnlock(hgBuffer); SetClipboardData(CF_TEXT, hgBuffer); CloseClipboard(); return true; } DataXY constructor that works in the code:
DataXY::DataXY(const QPixmap &pix) { this->finishedSearchButtonStartTask = false; this->pixmap = pix; this->createScreen(); this->screenDataHeight = this->pixmap.height(); this->screenDataWidth = this->pixmap.width(); } Copy constructor, DataXY constructor and destructor
void DataXY::createScreen() { QScreen *screen = QGuiApplication::primaryScreen(); if(screen) { this->pixmap = screen->grabWindow(0); } else { cerr << "Error createing Screenshot" << endl; } delete screen; } DataXY::DataXY(QObject *parent) : QObject(parent) { this->createScreen(); this->screenDataHeight=this->screenDataWidth=0; this->finishedSearchButtonStartTask = false; } DataXY::~DataXY() { } DataXY::DataXY(const QPixmap &pix) { this->finishedSearchButtonStartTask = false; this->pixmap = pix; this->createScreen(); this->screenDataHeight = this->pixmap.height(); this->screenDataWidth = this->pixmap.width(); // this->img = this->pixmap.toImage(); } DataXY::DataXY(const DataXY &dat) { this->leftLowerBound = dat.leftLowerBound; this->leftUpperBound = dat.leftUpperBound; this->rightLowerBound = dat.rightLowerBound; this->rightUpperBound = dat.rightUpperBound; this->leftLowerMargin = dat.leftLowerMargin; this->leftUpperMargin = dat.leftUpperMargin; this->rightLowerMargin = dat.leftLowerMargin; this->rightUpperMargin = dat.leftUpperMargin; this->screenDataHeight = dat.getScreenDataHeight(); this->screenDataWidth = dat.getScreenDataWidth(); this->pixmap = dat.getPixmap(); // this->img = this->pixmap.toImage(); this->finishedSearchButtonStartTask = dat.finishedSearchButtonStartTask; this->createScreen(); }