Results 1 to 20 of 29

Thread: Having trouble clearing a QTreeWidget.

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2007
    Posts
    158
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    25

    Default Re: Having trouble clearing a QTreeWidget.

    Yes, great idea

    Link to the project archived in ZIP format
    Link to the project archived in RAR format

    I should have taken a MVC approach, yes, but this project was just a small personnal project in order to list me what movies I have on my computer. I made the first build very simply, and I didn't took care about the conceptual approach... Shame on me !
    That's the reason why I didn't read all the informations relative to QTreeWidget in the Qt Assistant, and didn't saw the View and Model aspects avaibled for this widget .
    After that I developped more and more small functionnality, when I needed them. The project isn't really well concepted...

    My project is compounded of :
    - Listeur class, the main class that set the interface and lauch the various threads used by my application.
    - Interface_impl class, the interface implementation class that handle the user actions and wishes.
    - Thread_scanneur class, that search on my HDD in order to list the movies.
    - Thread_HTTP_XXX classes, that search on websites (1 class by website) in order to find, download and store the movies covers and resumes.

    So the 3 classes that manage QTreeWidgetItem* are :
    - Listeur
    - Interface_impl
    - Thread_scanneur

    The class that actually make the application to crash is Interface_impl.
    The signal concerned is : itemSelectionChanged().
    The slot concerned by this signal is : SLOT_selection_changed().

    The goal of this slot is to :
    - store all the items selected by the user
    - get the FIRST item selected in order to know the movie name that has been selected
    - display the cover and the resume of this movie on the interface
    Actually all this stuff is commented in the slot.

    There is no need to clear the QTreeWidget for doing that job...
    In reallity, the application used to crash when the user selected a movie, and then asked for an update of the movie list. This update was clearing the QTreeWidget in order to display the list of movies found on the HDD... And at this time, the application used to crash.

    So, in order to simplify the tests, I decided to clear() the QTreeWidget directly in the SLOT called when the selection changed.

    Thanks a lot for your help Wysota, as usually !



    EDIT : I've not really backtraces or debugger under the hand.
    I simply displays some comments on the cout at each step, in order to detect and target where the application crashes.

    EDIT : Attached the project source archived in ZIP format.
    Attached Files Attached Files
    Last edited by Nyphel; 9th October 2007 at 16:08.

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

    Default Re: Having trouble clearing a QTreeWidget.

    Khyym... please use the attachment feature of the forum next time. We don't like external links here.

    I should have taken a MVC approach, yes, but this project was just a small personnal project in order to list me what movies I have on my computer. I made the first build very simply, and I didn't took care about the conceptual approach... Shame on me !
    That's the reason why I didn't read all the informations relative to QTreeWidget in the Qt Assistant, and didn't saw the View and Model aspects avaibled for this widget .
    That's usually the problem. You start with something simple and suddenly it happens to be a big project. You're wasting much effort operating on the filesystem and you could have just used QDirModel with an optional proxy model to filter out entries you didn't want. You should think about redesigning it...


    EDIT : I've not really backtraces or debugger under the hand.
    I simply displays some comments on the cout at each step, in order to detect and target where the application crashes.
    That's not good, because what's important is not only that where the application crashes but also which method invoked the method that crashed and with what parameters. Unless you provide us with something small and compilable, you have to provide the backtrace yourself. Currently there's just too much code to analyse. It could be that the crash is caused by one of the threads (from what I understand you are using threads). Don't you by any chance operate on the tree from within a worker thread? Anyway please provide the backtrace or cut down the project to something small that reproduces the problem.

  3. #3
    Join Date
    Feb 2007
    Posts
    158
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    25

    Default Re: Having trouble clearing a QTreeWidget.

    Oki, I've attached the source code in the previous post .

    So, how may I produce the fully backtrace for my code ?
    I'm under Windows XP Pro SP2, using Eclipse as text editor.
    I've recently added the Qt Plugin for Eclipse in order to managed my .pro file, to use the API code completion, to build and run my project...

    But I've no idea about what concerns the backtraces/debugger functionalities of Qt and/or the Eclipse integration.

    My Qt is compiled in release/shared configuration.
    Should I rebuild it in debug/shared configuration ?



    PS : I'm sure that the crash isn't caused by a Thread.
    The application crashes when no Thread is started, I can make it crash just after the launch if necessary. My thread are only started on user ask, by clicking buttons on the interface et traces are displayed on the cout when the run() method is called.
    Moreover, I've decided that no thread would modify the QTreeWidget. So only Listeur and Interface_impl classes can modify the QTreeWidget, I prefer that...

    But I understand why the backtrace is necessary
    Last edited by Nyphel; 9th October 2007 at 16:19.

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

    Default Re: Having trouble clearing a QTreeWidget.

    Quote Originally Posted by Nyphel View Post
    Oki, I've attached the source code in the previous post .
    Yes, I know, but I assume that it's a bit too complex to understand it in 5 minutes.

    So, how may I produce the fully backtrace for my code ?
    I'm under Windows XP Pro SP2, using Eclipse as text editor.
    I've recently added the Qt Plugin for Eclipse in order to managed my .pro file, to use the API code completion, to build and run my project...
    If you're using MinGW as your compiler, you need to install gdb (GNU Debugger) and run your application under its control. When it crashes, type in "bt", press enter and paste in the result here. Just remember to compile your app in debug mode.

    Should I rebuild it in debug/shared configuration ?
    Not necessarily. You can compile your app in debug mode and link it against release Qt libs. But if you're not certain you can do it, it's better to compile Qt in debug mode as well.

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

    Nyphel (10th October 2007)

  6. #5
    Join Date
    Feb 2007
    Posts
    158
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    25

    Default Re: Having trouble clearing a QTreeWidget.

    I'm back

    In order to remove all doubt, I uninstalled Qt.
    I reinstalled Qt with the MinGW download.
    I reconfigured it with the following options : "-debug -release -shared".
    I re-built Qt without errors or warnings using "make sub-src".
    I built the Qt Debug Librairies without errors or warnings.

    I installed GDB (for MinGW).
    I reinstalled the Eclipse Qt Integration tool.

    I modified the .PRO file in order to add "Config += Debug".
    I launched my Qt Command Prompt.
    I built my application with "qmake" and "make".

    I' launched the GDB tool with "gdb release/Listeur" :
    Qt Code:
    1. Setting up a MinGW/Qt only environment...
    2. -- QTDIR set to D:\Applications\Qt\4.3.1
    3. -- PATH set to D:\Applications\Qt\4.3.1\bin
    4. -- Adding D:\Applications\MinGW\bin to PATH
    5. -- Adding C:\WINDOWS\System32 to PATH
    6. -- QMAKESPEC set to win32-g++
    7.  
    8. D:\Applications\Qt\4.3.1\Workspace\Listeur>gdb release/Listeur
    9. GNU gdb 6.3
    10. Copyright 2004 Free Software Foundation, Inc.
    11. GDB is free software, covered by the GNU General Public License, and you are
    12. welcome to change it and/or distribute copies of it under certain conditions.
    13. Type "show copying" to see the conditions.
    14. There is absolutely no warranty for GDB. Type "show warranty" for details.
    15. This GDB was configured as "i686-pc-mingw32"...(no debugging symbols found)
    To copy to clipboard, switch view to plain text mode 

    Next, I ran my application under control of GDB :
    Qt Code:
    1. (gdb) run
    2. Starting program: D:\Applications\Qt\4.3.1\Workspace\Listeur/release/Listeur.exe
    3.  
    4. ---Type <return> to continue, or q <return> to quit---
    To copy to clipboard, switch view to plain text mode 

    Of course, I pressed my RETURN key.
    The application has been launched.
    I selected an item of my QTreeWidget, and the application crashed :
    Qt Code:
    1. Program received signal SIGSEGV, Segmentation fault.
    2. 0x00446d3b in ?? ()
    To copy to clipboard, switch view to plain text mode 

    I typed in "bt", and here is what GDB returned me :
    Qt Code:
    1. (gdb) bt
    2. #0 0x00446d3b in ?? ()
    3. #1 0x0023979c in ?? ()
    4. #2 0x01543350 in ?? ()
    5. #3 0x10180418 in ZeqRK6QRectFS1_ ()
    6. from D:\Applications\Qt\4.3.1\bin\QtCore4.dll
    7. #4 0x10009f40 in ZN18QThreadStorageData6finishEPPv ()
    8. from D:\Applications\Qt\4.3.1\bin\QtCore4.dll
    9. #5 0x00455f40 in ?? ()
    10. #6 0x004a871b in ?? ()
    11. #7 0x002397cc in ?? ()
    12. #8 0x00446e42 in ?? ()
    13. #9 0x0023973c in ?? ()
    14. #10 0x00000001 in ?? ()
    15. #11 0x00000000 in ?? () from
    16. #12 0x00000027 in ?? ()
    17. #13 0x00239894 in ?? ()
    18. #14 0x002397e4 in ?? ()
    19. #15 0x00ba8372 in ZN11QMainWindow11qt_metacallEN11QMetaObject4CallEiPPv ()
    20. #16 0x0023a31c in ?? ()
    21. (gdb)
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: Having trouble clearing a QTreeWidget.

    Hmm... this doesn't look like debug mode And if the data is correct, it means your application has gone mad. Omit the "-release" switch when compiling Qt (or use -debug_and_release instead of -debug and -release). And make sure you add "CONFIG+=debug" to the project file (I'm not sure if it's case sensitive or not).

    Based on what we have here I'm sure your application uses threads (behind the scene, probably if you're not aware of it). Hard to say what exactly happens here without a proper backtrace.

  8. #7
    Join Date
    Feb 2007
    Posts
    158
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    25

    Default Re: Having trouble clearing a QTreeWidget.

    Oki, I've edited my .PRO file.

    A GDB run on "release/Listeur" returned me the same backtrace as the previous one, displayed above.

    Like my built of the application ("qmake", "make") outputs 2 executables ("release/Listeur.exe" and "debug/Listeur.exe"), I've made a GDB run on "debug/Listeur". It returned me the following backtrace :
    Qt Code:
    1. D:\Applications\Qt\4.3.1\Workspace\Listeur>gdb debug/Listeur
    2. GNU gdb 6.3
    3. Copyright 2004 Free Software Foundation, Inc.
    4. GDB is free software, covered by the GNU General Public License, and you are
    5. welcome to change it and/or distribute copies of it under certain conditions.
    6. Type "show copying" to see the conditions.
    7. There is absolutely no warranty for GDB. Type "show warranty" for details.
    8. This GDB was configured as "i686-pc-mingw32"...
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. (gdb) run
    2. Starting program: D:\Applications\Qt\4.3.1\Workspace\Listeur/debug/Listeur.exe
    To copy to clipboard, switch view to plain text mode 
    The application started correctly.

    Then, I made it crash, selected an item in my QTreeWidget :
    Qt Code:
    1. warning: ASSERT failure in QList<T>::at: "index out of range", file ../../includ
    2. e/QtCore/../../src/corelib/tools/qlist.h, line 386
    3.  
    4.  
    5. Program exited with code 01.
    To copy to clipboard, switch view to plain text mode 

    Now, I'm re-configuring and re-building Qt in debug mode only.
    See you tomorrow

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

    Default Re: Having trouble clearing a QTreeWidget.

    Wait, now we see you are accesing an item in a list that doesn't exist. It's probably your
    Qt Code:
    1. item_name = ((tree->selectedItems()).at(0))->text(0);
    To copy to clipboard, switch view to plain text mode 
    line. selectedItems() is probably empty. Try changing the above line to:
    Qt Code:
    1. QList<QTreeWidgetItem*> sel = tree->selectedItems();
    2. qDebug("ITEMS SELECTED: %d", sel.count());
    3.  
    4. if(!sel.isEmpty()){
    5. item_name = sel.at(0)->text(0);
    6. }
    To copy to clipboard, switch view to plain text mode 

  10. #9
    Join Date
    Feb 2007
    Posts
    158
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    25

    Default Re: Having trouble clearing a QTreeWidget.

    Hello,

    I've re-configured and re-built Qt in debug mode.

    I've tested my code under GDB and I got the same backtrace as before (the one in the above message).

    I've tested your code under GDB and I got the following backtrace :
    Qt Code:
    1. D:\Applications\Qt\4.3.1\Workspace\Listeur>gdb debug/Listeur
    2. GNU gdb 6.3
    3. Copyright 2004 Free Software Foundation, Inc.
    4. GDB is free software, covered by the GNU General Public License, and you are
    5. welcome to change it and/or distribute copies of it under certain conditions.
    6. Type "show copying" to see the conditions.
    7. There is absolutely no warranty for GDB. Type "show warranty" for details.
    8. This GDB was configured as "i686-pc-mingw32"...
    9. (gdb) run
    10. Starting program: D:\Applications\Qt\4.3.1\Workspace\Listeur/debug/Listeur.exe
    11. warning: ITEMS SELECTED: 1
    12.  
    13. warning: ITEMS SELECTED: 0
    To copy to clipboard, switch view to plain text mode 
    At this step the QTeeWidget is cleared and the application crashed.

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

    Default Re: Having trouble clearing a QTreeWidget.

    So as you see there are no items selected so you can't call at(0). You have to redesign the method.

  12. #11
    Join Date
    Feb 2007
    Posts
    158
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    25

    Default Re: Having trouble clearing a QTreeWidget.

    Yes, but I still don't understand the problem.

    void QTreeWidget::itemSelectionChanged () [signal]
    This signal is emitted when the selection changes in the tree widget. The current selection can be found with selectedItems()
    It appears that the signal itemSelectionChanged() has been emited 2 times. This is strange... The first time we have 1 item selected : that's OK, I select 1 item in the QTreeWidget. But why is the list empty ?! It should contains the item, like it is described in the Assistant :

    QList<QTreeWidgetItem *> QTreeWidget::selectedItems () const
    Returns a list of all selected non-hidden items.
    See also itemSelectionChanged().
    So I can't understand :
    - Why the signal has been emited 2 times (1 just clic 1 item, 1 time, with 1 clic)
    - Why the function isEmpty() returns "true", where as count() returns "1".

    Have you got an idea ?

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

    Default Re: Having trouble clearing a QTreeWidget.

    If isEmpty() returns true, count() has to return 0. There is no other way, you must be messing something up. I can't say why the selection is empty in your case - maybe you are mixing the selected and the current item? Current item doesn't have to be selected...

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

    Nyphel (10th October 2007)

Similar Threads

  1. resizing a QTreeWidget
    By drhex in forum Qt Programming
    Replies: 6
    Last Post: 27th October 2006, 22:32

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
  •  
Qt is a trademark of The Qt Company.