Hi,
Maybe too much hours working, maybe I have been looking the code for too much time, maybe I don't understand exactly the documentation, or maybe there are no error, but I have some memory leaks with this code and I feel unable to find a solution. I'm trying to load from a ui file a QMainWindow.
#include <QApplication>
#include <QTranslator>
#include <QObject>
#include <QUiLoader>
#include <QFile>
int main(int argc, char *argv[])
{
QMainDlg *mainWin = 0;
// Cargamos el archivo con las traducciones
if (translator.load("qt_es", app.applicationDirPath()) == false) {
QObject::trUtf8("Ha sido imposible cargar el fichero con las traducciones."));
} else {
app.installTranslator(&translator);
}
if ( QFile::exists(fileName
) ) { file.
open( QFile::ReadOnly );
QWidget *wid
= uiLoader.
load(&file,
0);
if ( wid != NULL ) {
wid->setAttribute(Qt::WA_DeleteOnClose);
wid->show();
}
file.close();
bool rc = app.exec();
return rc;
}
}
#include <QApplication>
#include <QTranslator>
#include <QObject>
#include <QUiLoader>
#include <QFile>
int main(int argc, char *argv[])
{
QMainDlg *mainWin = 0;
QApplication app(argc, argv);
// Cargamos el archivo con las traducciones
QTranslator translator;
if (translator.load("qt_es", app.applicationDirPath()) == false) {
QMessageBox::warning(0, QString::fromUtf8(APP_NAME),
QObject::trUtf8("Ha sido imposible cargar el fichero con las traducciones."));
} else {
app.installTranslator(&translator);
}
QString fileName = QString("/home/david/tmp/main.qmaindlg.ui");
QUiLoader uiLoader;
if ( QFile::exists(fileName) ) {
QFile file (fileName);
file.open( QFile::ReadOnly );
QWidget *wid = uiLoader.load(&file, 0);
if ( wid != NULL ) {
wid->setAttribute(Qt::WA_DeleteOnClose);
wid->show();
}
file.close();
bool rc = app.exec();
return rc;
}
}
To copy to clipboard, switch view to plain text mode
I simplify the main.qmaindlg.ui file to this:
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QMainDlg</class>
<widget class="QMainWindow" name="QMainDlg">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>790</width>
<height>126</height>
</rect>
</property>
<property name="windowTitle">
<string>Presupuestos - Pinelo Talleres Gráficos</string>
</property>
<property name="windowIcon">
<iconset>
<normaloff>:/aplicacion/recursos/icono_app_peque.png</normaloff>:/aplicacion/recursos/icono_app_peque.png</iconset>
</property>
<widget class="QWidget" name="centralwidget"/>
</widget>
<connections/>
</ui>
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QMainDlg</class>
<widget class="QMainWindow" name="QMainDlg">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>790</width>
<height>126</height>
</rect>
</property>
<property name="windowTitle">
<string>Presupuestos - Pinelo Talleres Gráficos</string>
</property>
<property name="windowIcon">
<iconset>
<normaloff>:/aplicacion/recursos/icono_app_peque.png</normaloff>:/aplicacion/recursos/icono_app_peque.png</iconset>
</property>
<widget class="QWidget" name="centralwidget"/>
</widget>
<connections/>
</ui>
To copy to clipboard, switch view to plain text mode
I use the Qt47supp.txt provides on Nokia Labs... The output of Valgrind is attached. You can see a lot of "definitely lost". valgrind.output.txt.zip
Is this normal? Something wrong with my code? I have no idea and I have several crashes on my applications, related with this, I think.
Thanks a lot.
Bookmarks