PDA

View Full Version : Model/View weird behaviour - Windows/Mingw



incapacitant
23rd March 2006, 21:16
Code 1, works. Code 2, aborts on launch (caught by Windows)

Code 1:


// destinataires
qDestin = new QListView( this );
qDestin->resize( QSize( 330, 110 ) );
qDestin->move( 34, 71 );

// setupModel
model = new QStandardItemModel(0, 1, this);
qDestin->setModel(model);
qDestin->setSelectionMode( QListView::MultiSelection );


Code 2:


// destinataires
qDestin = new QListView( this );
qDestin->resize( QSize( 330, 110 ) );
qDestin->move( 34, 71 );
qDestin->setModel(model);
qDestin->setSelectionMode( QListView::MultiSelection );

// setupModel
model = new QStandardItemModel(0, 1, this);



And code 2 generates no compile error from MINGW.


How can this be explained ?

jpn
23rd March 2006, 21:23
How can this be explained ?
In code 1, you instantiate the model correctly before passing it to the view.
And in code 2 you pass an uninitialized pointer...

jacek
23rd March 2006, 21:25
How can this be explained ?
In two words: unitialized pointer

PS. Do you have warnings enabled (CONFIG += warn_on)?

incapacitant
23rd March 2006, 21:36
yes warn_on is there in C:\Qt\4.1.1\mkspecs\win32-g++\qmake.conf :



#
# qmake configuration for win32-g++
#
# Written for MinGW
#

MAKEFILE_GENERATOR = MINGW
TEMPLATE = app
CONFIG += qt warn_on release link_prl copy_dir_files precompile_header
QT += core gui
DEFINES += UNICODE QT_LARGEFILE_SUPPORT
QMAKE_COMPILER_DEFINES += __GNUC__ WIN32

QMAKE_EXT_OBJ = .o

QMAKE_CC = gcc
QMAKE_LEX = flex



As far as I know even Basic would complain about an undefined variable in code 2.
Or have I missed something about C++ (again) ?

wysota
23rd March 2006, 21:49
It's not undefined. It is uninitialised (meaning it contains some random value). You probably defined it as a member variable.

jacek
23rd March 2006, 21:58
yes warn_on is there
Then maybe you initialize it to 0 in constructor or you haven't noticed the warning?


As far as I know even Basic would complain about an undefined variable
AFAIK it would just define that variable itself (at least VB) ;)

incapacitant
23rd March 2006, 22:04
yes it is defined in the class as private member. Is being a member means be defined and allocated ? If the compiler is able to spot unused variable, why is it not possible to spot uninitialized variables ?

AFAIK means ??

wysota
23rd March 2006, 22:21
yes it is defined in the class as private member. Is being a member means be defined and allocated ? If the compiler is able to spot unused variable, why is it not possible to spot uninitialized variables ?
Maybe you need to enable some option of the compiler?


AFAIK means ??
"As far as I know"