Difference in release and debug versions



  • I have such code:
    @ImageWidget::ImageWidget( QWidget * parent, const QString & filename ) : QWidget(parent)
    {
    m_imageLabel = new QLabel();
    m_imageLabel->setBackgroundRole(QPalette::Base);
    m_imageLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
    m_imageLabel->setScaledContents(true);

    m_scrollArea = new QScrollArea(this);
    m_scrollArea->setBackgroundRole(QPalette::Dark);
    m_scrollArea->setWidget(m_imageLabel);

    QVBoxLayout * layout = new QVBoxLayout();
    layout->addWidget(m_scrollArea);
    setLayout(layout);

    setWindowTitle(filename);
    resize(500, 400);

    // open file

    m_image = QImage(filename);
    if (m_image.isNull()) {
    QMessageBox::information(this, tr("Warning"),
    tr("Cannot load %1.").arg(filename));
    return;
    }

    m_imageLabel->setPixmap(QPixmap::fromImage(m_image));

    m_scaleFactor = 1.0;
    normalSize();

    m_pixelatorFlag = false;

    //connect(parent->ui.actionPixelator, SIGNAL(triggered()), this, SLOT(pixelatorOn()));

    m_difference = 20;
    m_currentColor = Qt::black;
    }@

    So when I run in debug I have m_image.isNull() = false, and program works correctle, but when making release and execute it on computer without Qt installed (I mean only my *.exe and core,gui dlls) m_image.isNull() = false. So m_image is QImage (not pointer), and filename gets here:

    @void MainWnd::onOpen()
    {
    QStringList files = QFileDialog::getOpenFileNames(this, "Select one or more files to open", "", "Images (*.png *.bmp *.jpeg *.jpg)");

    for(int i = 0; i<files.count();i++)
    createChildWindow(files.at(i));
    }@

    Then :

    @void MainWnd::createChildWindow(QString fileName)
    {
    ImageWidget * widget = new ImageWidget(this,fileName);
    connect(widget,SIGNAL(colorSelected(const QString & , int, int)),m_prcPanel, SLOT(showColorCoord(const QString &, int, int)));
    connect(m_prcPanel->m_difference,SIGNAL(valueChanged(int)),widget,SLOT(onChangeDifference(int)));

    QMdiSubWindow * window = m_area->addSubWindow(widget);
    if (window) {
    window->setAttribute(Qt::WA_DeleteOnClose, true);
    m_area->setActiveSubWindow(qobject_cast<QMdiSubWindow *>--(widget));
    widget->show();
    }
    }@



  • you can try do something like this:

    @bool isError = true;
    if(filename.isEmpty() == flase && QFile::exists(filename)){
    m_image = QImage(filename);
    if (m_image.isNull() == false)
    isError = false;
    }
    if(isError){
    QMessageBox::information(this, tr("Warning"),
    tr("Cannot load %1.").arg(filename));
    return;
    }
    }@



  • This is not actually problem. I mean I need to know why this happens ? The filename is not empty but the QImage is clear.


Log in to reply
 

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