Function doesn't work properly when called from an object
-
So I am experiencing something weird in my program.
I am using a function from a static library. And the static library is linked to a .dll. The function takes an image file and converts it to a TIFF file.
When I call the function from the main of my program, it gives me a correct output. That is even before the main window is displayed.
But when I call the function from a Dialog window (which is what I want my program to do), the function doesn't work properly. It creates a tiff files which is not correct.
I have noticed that the tiff file is always 262 143KB.I need help please. Don't understand what is happening.
-
Show us some code, please.
-
This is my very simple main:
@
#include <QApplication>
#include "mainwindow.h"int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MainWindow main;
main.show();
return app.exec();
}
@This is my main window class:
@
#include "MainWindow.h"
#include "batchwindow.h"
#include "importisqfiles.h"
#include <iostream>#define WIDTH 500
#define HEIGHT 100using namespace std;
void isq2tif(string isqImageName);MainWindow::MainWindow()
{
createActions();
createMenus();
createToolBar();
createStatusBar();connect(this, SIGNAL(startISQImport(string)), this,SLOT(import(string))); setFixedSize(WIDTH, HEIGHT); setWindowIcon(QIcon("png/strax.png")); setWindowTitle(tr("strAx")); //disable main window context menu setContextMenuPolicy(Qt::NoContextMenu);
}
void MainWindow::createActions()
{
//some code
}void MainWindow::createMenus()
{
//some code
}void MainWindow::createToolBar()
{
//some code
}void MainWindow::createStatusBar()
{
//some code
}void MainWindow::batchProcessing()
{
//some code
}void MainWindow::getISQFiles()
{
QFileDialog *browser = new QFileDialog(this); //browser dialog to get isq files path
QStringList fileList; //list of isq files//stores file paths fileList = browser->getOpenFileNames(0,"Choose ISQ files", QString(),"*.isq"); //delete browser delete browser; //transmit file list emit ISQfilesSelected(fileList);
}
void MainWindow::openISQ(QStringList files)
{
importISQFiles *ISQWindow;
ISQWindow = new importISQFiles(this,files);
ISQWindow->show();connect(ISQWindow, SIGNAL(startImporting(QStringList)),this,SLOT(ISQImport(QStringList)));
}
void MainWindow::importISQProcess(string isqToImport)
{
QString message("importing isq files...");
//QString fileName(isqToImport);
//message.append(fileName);emit startISQImport(isqToImport); isq2tif("D:/importISQTests/ISQtest/81-418-c0000508 Tibia.isq");
}
void MainWindow::ISQImport(QStringList files)
{
for(int i = 0; i < files.size(); ++i){
importISQProcess(files.at(i).toLocal8Bit().constData());
}
}@
I want to perform the following task:
When the import button is pressed, a browser is open to choose the *isq files to import (void MainWindow::getISQFiles()). The list of files is used to construct an import window. On the import window, when the import button is clicked, the import window is closed and the function void MainWindow::ISQImport(QStringList files) is called. This function will the convert each *isq files to a tiff file using the function void isq2tif(string fileName).The program does all these steps and converts files to tiff. However, the tiff file is not correct. It is always 255Mb. In fact when the isq file is too big (more that about 250MB), the tiff file is always 255MB.
I have monitored the conversion on the windows task manager and I have notices that it always stops converting when program is at about 590MB in memory.
The strange thing is, if I call the function form the main, I dont have any size limitation and the tiff file is correct.
-
@connect(this, SIGNAL(startISQImport(string)), this,SLOT(import(string)));@
You did not show use the function/slot "import(string)". How does it look like?
(I only see an "ISQImport" function. If you intended to connect to that one, you connect() code is wrong)
--
BTW: The toLocal8Bit() function will screw up all characters that happen to not be representable in the computer's local 8-Bit codepage, which can be different on every computer. Instead use toUtf8() and make isq2tif() UTF8-aware. Or even better: Make that function take a const reference to a QString rather than a C string.