Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 3

Qt-interest Archive, December 2006
Dialogs, parents, and memory with Model View Controller Architecture


Message 1 in thread

First I would like to apologize if this is only tangentially Qt related.

I am implementing a model-view-controller framework for my Qt image analysis application, where a QGraphicsView is the view, and I am implementing my own model and controller.

I am trying to pass a pointer to the main window down through the viewer class to the model class, so that it can open a QFileDialog as a child of the main window.  This works fine in "release" mode, but when I run the application in "debug" mode, gdb crashes with this complaint:

BFD: C:\WINDOWS\system32\wmvcore.dll (.reloc): Section flag IMAGE_SCN_MEM_NOT_PAGED (0x8000000) ignored

Perhaps this is a gdb bug, but allow me to post a small snippet that can reproduce the error.  When compiled in debug mode (on my Windows XP system, with mingw, gcc 3.4.2 and gdb 5.2.1), I get the above error when I start typing in the "File name" text box (after clicking the "Open Image" button that signals the openFiles() slot.).  The application continues until I click "Open" to close the file dialog, then gdb bails and the application bails.  (Note the error does not occur if I simple double click a file rather than typing in the File name text box).

Am I doing something stupid here, such as screwing up the parent-child relationships between the windows?

Thanks,
-Eric

---------8<----------dialogimpl.h-------------
#ifndef DIALOGIMPL_H
#define DIALOGIMPL_H

#include "ui_dialog.h"
#include "QFileDialog"


class Model : public QObject
{
Q_OBJECT

public:
  Model(QWidget*);
  void openFiles();
		
private:
  QWidget *parent;
};

class View : public QObject
{
Q_OBJECT
public:
  View(QWidget*);
  void openModelFiles();
	
private:
  Model *model;	
};

class DialogImpl : public QMainWindow, public Ui::Dialog
{
Q_OBJECT
public:
  DialogImpl( QWidget * parent = 0, Qt::WFlags f = 0 );

public slots:
  void openFiles();

private slots:

private:
  Ui::Dialog ui;
  View *view;
};

#endif

---------8<----------dialogimpl.cpp-------------

#include "dialogimpl.h"

DialogImpl::DialogImpl( QWidget * parent, Qt::WFlags f)
	: QMainWindow(parent, f)
{
	ui.setupUi(this);
	QObject::connect(ui.OpenFiles, SIGNAL(clicked()), this, SLOT(openFiles()));
	view = new View(this);
}

void DialogImpl::openFiles() {
	view->openModelFiles();
}

View::View(QWidget* parent) : QObject(parent)
{
	model = new Model(parent);
}

void View::openModelFiles() {
	model->openFiles();
}


Model::Model(QWidget* app) : QObject(app)
{	
	parent = app;
}

void Model::openFiles() {
 QList <QImage*> image;
 QStringList files = QFileDialog::getOpenFileNames(parent,
                          tr("Open File"),
                          "/",
                          tr("Images (*.tif; *.TIF; .jpg; .JPG)"));
  return;
}

#include <QApplication>
#include "dialogimpl.h"

---------8<----------main.cpp-------------

int main(int argc, char ** argv)
{
	QApplication app( argc, argv );
	DialogImpl win;
	win.show();
	app.connect( &app, SIGNAL( lastWindowClosed() ), &app, SLOT( quit() ) );
	return app.exec();
}

---------8<----------dialog.ui-------------
<ui version="4.0" >
 <class>Dialog</class>
 <widget class="QMainWindow" name="Dialog" >
  <property name="geometry" >
   <rect>
    <x>0</x>
    <y>0</y>
    <width>598</width>
    <height>388</height>
   </rect>
  </property>
  <property name="windowTitle" >
   <string>MainWindow</string>
  </property>
  <widget class="QWidget" name="centralwidget" >
   <widget class="QPushButton" name="OpenFiles" >
    <property name="geometry" >
     <rect>
      <x>60</x>
      <y>60</y>
      <width>75</width>
      <height>24</height>
     </rect>
    </property>
    <property name="text" >
     <string>Open Files</string>
    </property>
   </widget>
  </widget>
  <widget class="QMenuBar" name="menubar" >
   <property name="geometry" >
    <rect>
     <x>0</x>
     <y>0</y>
     <width>598</width>
     <height>19</height>
    </rect>
   </property>
  </widget>
  <widget class="QStatusBar" name="statusbar" />
 </widget>
 <resources/>
 <connections/>
</ui>

---------8<----------test.pro-------------

TEMPLATE =   app
QT +=   gui \
  core
CONFIG +=   qt \
  warn_on \
  console \
  debug_and_release
FORMS =   dialog.ui
HEADERS =   dialogimpl.h
SOURCES =   dialogimpl.cpp \
  main.cpp




--
 [ signature omitted ]