Results 1 to 20 of 22

Thread: Problems with setCentralWidget

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2008
    Posts
    28
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Problems with setCentralWidget

    Hello all,

    I have this code

    Qt Code:
    1. class QTWindowView : public WindowView, public QTextEdit{
    2. public:
    3. QString getText() const;
    4. void setText(const QString & text);
    5. };
    To copy to clipboard, switch view to plain text mode 

    and when I try to setCentralWidget with this class on QMainWindow
    I get a segmentation fault.
    whats more, on Windows the code DOES work, but on linux
    it crash

    any suggestions ?
    Eli
    Last edited by jpn; 8th March 2008 at 12:01. Reason: missing [code] tags

  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: Problems with setCentralWidget

    Hard to say with given code, but at least QTextEdit should be the first in the inheritance list if you ever plan to add any Qt meta system stuff to your class. Could you paste backtrace from gdb by the time of crash?
    J-P Nurmi

  3. #3
    Join Date
    Feb 2008
    Posts
    28
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problems with setCentralWidget

    this is the backtrace:
    Program received signal SIGSEGV, Segmentation fault.
    [Switching to Thread -1225295584 (LWP 4130)]
    0xb77e5b11 in QWidget::isAncestorOf (this=0x8097140, child=0x804ca08) at kernel/qwidget.cpp:6049
    /home/elis/downloads/qt-x11-opensource-src-4.3.4/src/gui/kernel/qwidget.cpp:6049:181840:beg:0xb77e5b11


    Eli

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

    Default Re: Problems with setCentralWidget

    This is not a backtrace. Use the "bt" command in gdb.

  5. #5
    Join Date
    Feb 2008
    Posts
    28
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problems with setCentralWidget

    ok, thanx ..

    #0 0xb77e5b11 in QWidget::isAncestorOf (this=0x8097140, child=0x804ca08) at kernel/qwidget.cpp:6049
    #1 0xb77f3b02 in QWidget::setParent (this=0x8097140, parent=0x80ce47c, f=@0xbf83af20) at kernel/qwidget.cpp:7643
    #2 0xb77f3f38 in QWidget::setParent (this=0x804ca08, parent=0x8097140) at kernel/qwidget.cpp:7616
    #3 0xb77cfb91 in QLayout::addChildWidget (this=0x80e85a8, w=0x8097140) at kernel/qlayout.cpp:931
    #4 0xb7af92f9 in QMainWindowLayout::setCentralWidget (this=0x80e85a8, widget=0x8097140) at widgets/qmainwindowlayout.cpp:1789
    #5 0xb7af7080 in QMainWindow::setCentralWidget (this=0x80ce47c, widget=0x8097140) at widgets/qmainwindow.cpp:554
    #6 0x0804e01b in QTMainWindowView::setCenterWidget (this=0x80ce478, view=0x8097140) at src/qt/qtmainwindowview.cpp:10
    #7 0x0804d01c in MainWindow (this=0xbf83b0b0) at src/mainwindow.cpp:17
    #8 0x0804e23c in runApp (app=@0xbf83b100, argc=1, argv=0xbf83b1b4) at tests/tests.cpp:34
    #9 0x0804e783 in main (argc=1, argv=0xbf83b1b4) at tests/tests.cpp:49
    Last edited by jpn; 8th March 2008 at 13:18. Reason: missing [quote] tags

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

    Default Re: Problems with setCentralWidget

    What is runApp() and QTMainWindowView?

  7. #7
    Join Date
    Feb 2008
    Posts
    28
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problems with setCentralWidget

    runApp:
    Qt Code:
    1. int runApp(QApplication& app, int argc, char** argv) {
    2. MainWindow::setViewFactory(new QTViewFactory);
    3. MainWindow mainWin;
    4. if(mainWin.evaluateArguments(argc, argv)) {
    5. mainWin.show();
    6. return app.exec();
    7. }
    8. return -1;
    9. }
    To copy to clipboard, switch view to plain text mode 
    QTWindowView:
    Qt Code:
    1. class QTMainWindowView : public MainWindowView, public QMainWindow {
    2. public:
    3. void show();
    4. void setCenterWidget(WidgetView* view);
    5. };
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: Problems with setCentralWidget

    1. QWidget::show() is not virtual,
    2. What's the contents of QTMainWindowView::setCenterWidget ?
    3. What is MainWindowView?
    4. I think you are lacking the Q_OBJECT macro somewhere, isAncestorOf() may be needing it, but it's hard to say that without seeing the whole code.

  9. #9
    Join Date
    Feb 2008
    Posts
    28
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problems with setCentralWidget

    [QUOTE]1. QWidget::show() is not virtual [QUOTE]
    I know

    2. What's the contents of QTMainWindowView::setCenterWidget ?
    Qt Code:
    1. void QTMainWindowView::show() {
    2. QMainWindow::show();
    3. }
    4.  
    5. void QTMainWindowView::setCenterWidget(WidgetView* view) {
    6. QMainWindow::setCentralWidget((QWidget*)view);
    7. }
    To copy to clipboard, switch view to plain text mode 
    WidgetView is my parent view for all the view classes (it's empty)

    3. What is MainWindowView?
    it is pure abstract class that defines the show and setCentralWidget

    4. I think you are lacking the Q_OBJECT macro somewhere, isAncestorOf() may be needing it, but it's hard to say that without seeing the whole code.
    ummmm .... ?

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

    Default Re: Problems with setCentralWidget

    Quote Originally Posted by Rockem View Post
    1. QWidget::show() is not virtual
    I know
    Good, so why do you reimplement it anyway?


    Qt Code:
    1. void QTMainWindowView::show() {
    2. QMainWindow::show();
    3. }
    4.  
    5. void QTMainWindowView::setCenterWidget(WidgetView* view) {
    6. QMainWindow::setCentralWidget((QWidget*)view);
    7. }
    To copy to clipboard, switch view to plain text mode 
    WidgetView is my parent view for all the view classes (it's empty)
    Why do you cast to QWidget* in line 6? If your compiler complains without that cast then that's probably your problem - your widget is not a widget...

    ummmm .... ?
    Yeah... "ummmm" is right... Start by changing the inheritance order as already suggested, remove the cast to QWidget and tell us why you need the additional two layers over QWidget...

  11. #11
    Join Date
    Feb 2008
    Posts
    28
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problems with setCentralWidget

    I'm using a Abstract Factory (Pattern)
    which means that I'm accessing all my views (=qt widgets) through
    interfaces (=abstract classes)
    that is why I need the to reimplement show()

    this is also why I have two more layers

    I also need the cast coz WidgetView is NOT QWidget.

Similar Threads

  1. Replies: 2
    Last Post: 8th March 2007, 22:22
  2. Utf8 problems
    By cristiano in forum Qt Programming
    Replies: 5
    Last Post: 11th November 2006, 00:14
  3. Problems building mysql plugin for Qt 4.1.2 on windows XP
    By Philip_Anselmo in forum Installation and Deployment
    Replies: 3
    Last Post: 17th May 2006, 15:38
  4. QT4 Plugins - problems, problems
    By NormanDunbar in forum Qt Programming
    Replies: 6
    Last Post: 9th May 2006, 15:39
  5. [Win32/VC++ 8.0] Strange problems with qrc_*.cpp files
    By mloskot in forum Installation and Deployment
    Replies: 6
    Last Post: 6th March 2006, 10:28

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.