Results 1 to 2 of 2

Thread: QT ImageViewer Tutorial crashes with QT Designer

  1. #1
    Join Date
    Oct 2017
    Posts
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default QT ImageViewer Tutorial crashes with QT Designer

    My development environment is Visual studio 2015 with QT 5.6.3. I am creating forms using QT designer. I am doing several QT tutorials; specifically I am doing the following tutorial.

    http://www.bogotobogo.com/Qt/Qt5_QMa...geViewer_B.php

    The program essentially, displays an image using QScrollArea and QLabel. The program works if I create my "widgets" in visual studio (without QT designer)

    //Here's the relevant code
    Qt Code:
    1. imageLabel = new QLabel;
    2. imageLabel->setBackgroundRole(QPalette::Base);
    3. imageLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
    4. imageLabel->setScaledContents(true);
    5.  
    6. scrollArea = new QScrollArea;
    7. scrollArea->setBackgroundRole(QPalette::Dark);
    8. scrollArea->setWidget(imageLabel);
    9. setCentralWidget(scrollArea);
    To copy to clipboard, switch view to plain text mode 

    As expected the scrollbars appear.

    Then I created the widgets in QT Designer and tried to use it in visual studio. The one thing I noticed is that when I create a scrollArea using QT designer it also creates a QWidget called "ScrollAreaWidgetContents". See the attached "QT_Designer_1" and "QT_Inspector_Window" images. The problem is that I can't see scroll bars with this program. See the attached "Image_Viewer_No_ScrollBars". Here's the releavant code.

    Qt Code:
    1. ui->label->setBackgroundRole(QPalette::Base);
    2. ui->label->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
    3. ui->label->setScaledContents(true);
    4.  
    5. ui->scrollArea->setBackgroundRole(QPalette::Dark);
    6. ui->scrollArea->setWidget(ui->scrollAreaWidgetContents);
    7. ui->scrollArea->setWidgetResizable(true);
    8. ui->scrollAreaWidgetContents->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
    9. //ui->scrollArea->setWidget(ui->label);
    10. setCentralWidget(ui->scrollArea);
    To copy to clipboard, switch view to plain text mode 

    I then tried to uncomment "ui->scrollArea->setWidget(ui->label)" line and the program crashes. See the attached "Image_Viewer_Crashes" I guess I don't understand why it's crashing. Could anyone help resolve this problem?

    Thanks
    Attached Images Attached Images

  2. #2
    Join Date
    Oct 2017
    Posts
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: QT ImageViewer Tutorial crashes with QT Designer

    On designer as default scrollarea creating a central widget. This is the auto-generated code from designer and if you put your label into this content it will work. Or you can create your own class inherited from QLabel and promote that contents widget into your class and that will work too.

    Qt Code:
    1. scrollAreaWidgetContents = new QWidget();
    2. scrollAreaWidgetContents->setObjectName(QStringLiteral("scrollAreaWidgetContents"));
    3. scrollAreaWidgetContents->setGeometry(QRect(0, -460, 1920, 1080));
    4. verticalLayout = new QVBoxLayout(scrollAreaWidgetContents);
    5. verticalLayout->setSpacing(6);
    6. verticalLayout->setContentsMargins(11, 11, 11, 11);
    7. verticalLayout->setObjectName(QStringLiteral("verticalLayout"));
    8. verticalLayout->setContentsMargins(0, 0, 0, 0);
    9. label = new QLabel(scrollAreaWidgetContents);
    10. label->setObjectName(QStringLiteral("label"));
    11. label->setPixmap(QPixmap(QString::fromUtf8("../../../Pictures/chuukarudoruhu.jpg")));
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Designer plugin crashes when opening *.ui
    By dimm0n in forum Qt Tools
    Replies: 2
    Last Post: 12th April 2010, 08:40
  2. plugin crashes designer but not app
    By jayw710 in forum Qt Tools
    Replies: 1
    Last Post: 27th June 2007, 20:37
  3. Simple text editor with QT designer Tutorial
    By overcast in forum Qt Tools
    Replies: 2
    Last Post: 27th January 2007, 15:33
  4. tutorial qt designer
    By edancorr in forum Qt Programming
    Replies: 1
    Last Post: 26th October 2006, 20:07
  5. Interesting tutorial on UI Designer
    By GreyGeek in forum Qt Tools
    Replies: 1
    Last Post: 6th August 2006, 09:43

Tags for this Thread

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.