[Solved] UI form connection error



  • 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);
    }
    };
    @



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

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



  • 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);
    }
    };
    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.