Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Promoted CustomQScrollArea segfault

Promoted CustomQScrollArea segfault

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 1.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    phizla
    wrote on last edited by
    #1

    My actual use case is nontrivial, so I provide a small example that reproduces the segmentation fault:

    I have class CustomScrollArea that inherits QScrollArea:

    @
    class CustomScrollArea : public QScrollArea
    {
    Q_OBJECT
    public:
    explicit WarxingScrollArea(QWidget* parent=0);
    void segFaultThrowingMethod();
    private:
    QLabel* dynamicallyCreatedLabel;
    };
    @

    @
    CustomScrollArea::CustomScrollArea(QWidget* parent) : QScrollArea(parent)
    {
    dynamicallyCreatedLabel = new QLabel;
    setWidget(dynamicallyCreatedLabel);

    //this call will _not_ cause a seg fault
    segFaultThrowingMethod();
    

    }

    void CustomScrollArea::segFaultThrowingMethod()
    {
    dynamicallyCreatedLabel->setText("Some text");
    }
    @

    I have a MainWindow class with the following source:

    @
    class MainWindow : public QMainWindow
    {
    Q_OBJECT
    public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
    private:
    Ui::MainWindow *ui;
    };
    @

    @
    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);

    //this call will cause a seg fault
    ui->customScrollArea->segFaultThrowingMethod();
    

    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }
    @

    The .ui file for MainWindow contains a single QScrollArea promoted to a CustomQScrollArea. Its name is "customScrollArea".

    When I start the application, the first invocation of CustomScrollArea::segFaultThrowingMethod() occurs in CustomScrollArea's constructor for Ui::MainWindow::customScrollArea and passes without incident. However, when MainWindow invokes ui->customScrollArea->segFaultThrowingMethod(), a segmentation fault occurs.

    Note that the segmentation fault is not due to CustomScrollArea::dynamicallyCreatedLabel being null. The best clue I have is that this issue does not happen if MainWindow dynamically instantiates a CustomScrollArea rather than getting it from Ui::MainWindow. However, I would like to be able to use QScrollAreas promoted to CustomScrollAreas in Qt Designer.

    Thanks for any help!

    1 Reply Last reply
    0
    • P Offline
      P Offline
      phizla
      wrote on last edited by
      #2

      This has been answered at "stackoverflow":http://stackoverflow.com/questions/19987774/promoted-customqscrollarea-segmentation-fault. The problem is my promoting a QScrollArea. A promoted QScrollArea will have its constructor's setWidget() call overridden in ui->setupUi(). If I promote just a QWidget to a CustomScrollArea, I get around this. It feels like bad form, but it works.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved