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. [Solved] UI form connection error

[Solved] UI form connection error

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 863 Views
  • 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.
  • G Offline
    G Offline
    gerberka
    wrote on 7 Sept 2014, 10:29 last edited by
    #1

    I created widget in qt designer, and I want to connect widget's buttons with slots of my objects but when I add row with connection code my programm crash :( Thanks for answers!

    mainwindow.cpp
    @
    void MainWindow::AddImages(){
    ...
    Ui::ImageProperties ui;
    foreach (const QString &str, list) {
    QWidget widget = new QWidget;
    ui.setupUi(widget);
    ui.label->setText(str);
    ImageItem
    item = (ImageItem*)(scene->addPixmap(QPixmap(str)));
    connect(ui.checkBox,SIGNAL(stateChanged(int)),item,SLOT(changeVisibility(int)));
    images.append(item);
    propImagesLayout->addWidget(widget);
    }
    @

    mainwindow.h
    @
    QList<ImageItem*> images;
    QVBoxLayout* propImagesLayout;
    @
    imageitem class
    @
    class ImageItem : public QObject, public QGraphicsPixmapItem
    {
    Q_OBJECT
    public:
    ImageItem(QPixmap pixmap) : QGraphicsPixmapItem(pixmap){}

    public slots:
    void changeVisibility(int state){
    if(state == 0)hide();
    else show();
    }
    void changeOpacity(int level){
    setOpacity(level/10);
    }
    };
    @

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dheerendra
      Qt Champions 2022
      wrote on 7 Sept 2014, 11:15 last edited by
      #2

      ImageItem* item = (ImageItem*)(scene->addPixmap(QPixmap(str)));

      Just check above statement. Item is definitely null here. AddPixmap may not be working.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • G Offline
        G Offline
        gerberka
        wrote on 7 Sept 2014, 12:00 last edited by
        #3

        Thank you!
        I edit class ImageItem and programm work
        @
        class ImageItem : public QObject
        {
        Q_OBJECT
        private:
        QGraphicsPixmapItem *m_pixmap;
        public:
        ImageItem(QGraphicsPixmapItem *pixmap){
        m_pixmap = pixmap;
        }

        public slots:
        void changeVisibility(int state){
        if(state == 0)m_pixmap->hide();
        else m_pixmap->show();
        }
        void changeOpacity(int level){
        m_pixmap->setOpacity(level/10);
        }
        };
        @

        1 Reply Last reply
        0

        1/3

        7 Sept 2014, 10:29

        • Login

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