Results 1 to 8 of 8

Thread: Model/View weird behaviour - Windows/Mingw

  1. #1
    Join Date
    Jan 2006
    Location
    Grenoble, France
    Posts
    165
    Thanks
    106
    Qt products
    Qt4
    Platforms
    Windows

    Default Model/View weird behaviour - Windows/Mingw

    Code 1, works. Code 2, aborts on launch (caught by Windows)

    Code 1:
    Qt Code:
    1. // destinataires
    2. qDestin = new QListView( this );
    3. qDestin->resize( QSize( 330, 110 ) );
    4. qDestin->move( 34, 71 );
    5.  
    6. // setupModel
    7. model = new QStandardItemModel(0, 1, this);
    8. qDestin->setModel(model);
    9. qDestin->setSelectionMode( QListView::MultiSelection );
    To copy to clipboard, switch view to plain text mode 

    Code 2:
    Qt Code:
    1. // destinataires
    2. qDestin = new QListView( this );
    3. qDestin->resize( QSize( 330, 110 ) );
    4. qDestin->move( 34, 71 );
    5. qDestin->setModel(model);
    6. qDestin->setSelectionMode( QListView::MultiSelection );
    7.  
    8. // setupModel
    9. model = new QStandardItemModel(0, 1, this);
    To copy to clipboard, switch view to plain text mode 


    And code 2 generates no compile error from MINGW.


    How can this be explained ?

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Model/View weird behaviour - Windows/Mingw

    Quote Originally Posted by incapacitant
    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...

  3. The following user says thank you to jpn for this useful post:

    incapacitant (23rd March 2006)

  4. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Model/View weird behaviour - Windows/Mingw

    Quote Originally Posted by incapacitant
    How can this be explained ?
    In two words: unitialized pointer

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

  5. The following user says thank you to jacek for this useful post:

    incapacitant (23rd March 2006)

  6. #4
    Join Date
    Jan 2006
    Location
    Grenoble, France
    Posts
    165
    Thanks
    106
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Model/View weird behaviour - Windows/Mingw

    yes warn_on is there in C:\Qt\4.1.1\mkspecs\win32-g++\qmake.conf :

    Qt Code:
    1. #
    2. # qmake configuration for win32-g++
    3. #
    4. # Written for MinGW
    5. #
    6.  
    7. MAKEFILE_GENERATOR = MINGW
    8. TEMPLATE = app
    9. CONFIG += qt warn_on release link_prl copy_dir_files precompile_header
    10. QT += core gui
    11. DEFINES += UNICODE QT_LARGEFILE_SUPPORT
    12. QMAKE_COMPILER_DEFINES += __GNUC__ WIN32
    13.  
    14. QMAKE_EXT_OBJ = .o
    15.  
    16. QMAKE_CC = gcc
    17. QMAKE_LEX = flex
    To copy to clipboard, switch view to plain text mode 


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

  7. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Model/View weird behaviour - Windows/Mingw

    It's not undefined. It is uninitialised (meaning it contains some random value). You probably defined it as a member variable.

  8. The following user says thank you to wysota for this useful post:

    incapacitant (23rd March 2006)

  9. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Model/View weird behaviour - Windows/Mingw

    Quote Originally Posted by incapacitant
    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)

  10. The following user says thank you to jacek for this useful post:

    incapacitant (23rd March 2006)

  11. #7
    Join Date
    Jan 2006
    Location
    Grenoble, France
    Posts
    165
    Thanks
    106
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Model/View weird behaviour - Windows/Mingw

    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 ??

  12. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Model/View weird behaviour - Windows/Mingw

    Quote Originally Posted by incapacitant
    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"

  13. The following user says thank you to wysota for this useful post:

    incapacitant (24th March 2006)

Similar Threads

  1. Weird behaviour of mouse events and QMenu pop-ups
    By Ishark in forum Qt Programming
    Replies: 1
    Last Post: 7th August 2007, 07:46

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.