I'm using Qt 5.8.0 MinGW 32 bit from Qt Creator 4.2.1 on an HP desktop with a Intel Xeon CPU in Windows & Professional 64 bit service pack1 OS.
I keep getting a segmentation fault when running this code (in debug) at the point where I attempt to load an image using QPixmap.
I believe my pointers are initialized correctly nor can I notice any uninitialized pointers or out of bound arrays (unless I'm looking right at it and can't see it). In the following code, some of the documented out lines are various ways I've attempted to load the image.
Header file...
#ifndef OVERVIEW_H
#define OVERVIEW_H
#include <QDialog>
#include <QWidget>
#include <QGeoRectangle>
#include <QGraphicsScene>
#include <QGraphicsObject>
#include "aircraft.h"
namespace Ui {
class OverView;
}
{
Q_OBJECT
public:
explicit OverView
(QWidget* pParent
= 0);
~OverView();
private slots:
void showRange(int range); // Setup background
void on_closeBtn_clicked();
private:
Ui::OverView* ui;
void setUpWindow();
QString sRangeFileNm;
// Holds selected range file name
// QPixmap static rangePic; // The selected range image
//____________________________________________________________
// Range background images from the resource file data.qrc
QString sBothFileNm
= ":/Data/Images/BothRanges2000.gif";
QString sNorthFileNm
= ":/Data/Images/NorthRange2000_2000.gif";
QString sSouthFileNm
= ":/Data/Images/SouthRange2000_2000.gif";
};
#endif // OVERVIEW_H
#ifndef OVERVIEW_H
#define OVERVIEW_H
#include <QDialog>
#include <QWidget>
#include <QGeoRectangle>
#include <QGraphicsScene>
#include <QGraphicsObject>
#include "aircraft.h"
namespace Ui {
class OverView;
}
class OverView : public QDialog
{
Q_OBJECT
public:
explicit OverView(QWidget* pParent = 0);
~OverView();
private slots:
void showRange(int range); // Setup background
void on_closeBtn_clicked();
private:
Ui::OverView* ui;
void setUpWindow();
QString sMessage;
QString sRangeFileNm; // Holds selected range file name
// QPixmap static rangePic; // The selected range image
QGraphicsScene* pRangeScene; // Graphic scene pointer
//____________________________________________________________
// Range background images from the resource file data.qrc
QString sBothFileNm = ":/Data/Images/BothRanges2000.gif";
QString sNorthFileNm = ":/Data/Images/NorthRange2000_2000.gif";
QString sSouthFileNm = ":/Data/Images/SouthRange2000_2000.gif";
};
#endif // OVERVIEW_H
To copy to clipboard, switch view to plain text mode
cpp file...
#include "overview.h"
#include "ui_overview.h"
#include "ui_rddswindow.h"
OverView
::OverView(QWidget* pParent
) : ui(new Ui::OverView)
{
ui->setupUi(this);
setUpWindow();
showRange(0); // Set the default background
}
/*---- setUpWindow -------------------------------------------------------------------
Sets up the elements of the range view window. The combination box
allows user to select the range to use as background and connects the
combination box signal to the showRange slot.
*/
void OverView::setUpWindow()
{
setWindowTitle("Range View");
this->setObjectName("RangeView");
selectedRange << "Both Ranges" << "North Range"<< "Echo Range";
ui->rangeCmbBox->addItems(selectedRange);
QObject::connect(ui
->rangeCmbBox,
SIGNAL(currentIndexChanged
(int)),
this, SLOT(showRange(int)));
}
/*---- showRange --------------------------------------------------------------------------
Sets the background image and scaling based on an index value provided
by the rangeCmbBox in the range view.
0 - Both north and south ranges
1 - North range
2 - South range
*/
void OverView::showRange(int range)
{
sRangeFileNm.clear();
switch(range){
case 0: // Default image is both ranges
sRangeFileNm.append(sBothFileNm);
break;
case 1:
sRangeFileNm.append(sNorthFileNm); // North range image
break;
default:
sRangeFileNm.append(sSouthFileNm); // South range image
break;
}
// QPixmap const rangePic(sRangeFileNm);
rangeBackground.setTexture(rangePic);
ui->rangeView->setBackgroundBrush(rangeBackground);
ui->rangeView->setSceneRect(rangeRect);
ui->rangeView->show();
/*
if(rangePic.load(sRangeFileNm)){ // Load the range picture
rangeBackground.setTexture(rangePic);
ui->rangeView->setBackgroundBrush(rangeBackground);
QRectF rangeRect = QRectF(QPointF(0,0), rangePic.size());
ui->rangeView->setSceneRect(rangeRect);
ui->rangeView->show();
sMessage.append("Successfully loaded range image");
}else
sMessage.append("Failed to load range image");
*/
qDebug() << sMessage;
}
#include "overview.h"
#include "ui_overview.h"
#include "ui_rddswindow.h"
OverView::OverView(QWidget* pParent) :
QDialog(pParent),
ui(new Ui::OverView)
{
ui->setupUi(this);
setUpWindow();
showRange(0); // Set the default background
}
/*---- setUpWindow -------------------------------------------------------------------
Sets up the elements of the range view window. The combination box
allows user to select the range to use as background and connects the
combination box signal to the showRange slot.
*/
void OverView::setUpWindow()
{
setWindowTitle("Range View");
this->setObjectName("RangeView");
QStringList selectedRange;
selectedRange << "Both Ranges" << "North Range"<< "Echo Range";
ui->rangeCmbBox->addItems(selectedRange);
QObject::connect(ui->rangeCmbBox, SIGNAL(currentIndexChanged(int)),
this, SLOT(showRange(int)));
ui->rangeView->setDragMode(QGraphicsView::ScrollHandDrag);
}
/*---- showRange --------------------------------------------------------------------------
Sets the background image and scaling based on an index value provided
by the rangeCmbBox in the range view.
0 - Both north and south ranges
1 - North range
2 - South range
*/
void OverView::showRange(int range)
{
QBrush rangeBackground;
sRangeFileNm.clear();
switch(range){
case 0: // Default image is both ranges
sRangeFileNm.append(sBothFileNm);
break;
case 1:
sRangeFileNm.append(sNorthFileNm); // North range image
break;
default:
sRangeFileNm.append(sSouthFileNm); // South range image
break;
}
// QPixmap const rangePic(sRangeFileNm);
QPixmap const rangePic = QPixmap(sRangeFileNm);
rangeBackground.setTexture(rangePic);
ui->rangeView->setBackgroundBrush(rangeBackground);
QRectF rangeRect = QRectF(QPointF(0,0), rangePic.size());
ui->rangeView->setSceneRect(rangeRect);
ui->rangeView->show();
/*
if(rangePic.load(sRangeFileNm)){ // Load the range picture
rangeBackground.setTexture(rangePic);
ui->rangeView->setBackgroundBrush(rangeBackground);
QRectF rangeRect = QRectF(QPointF(0,0), rangePic.size());
ui->rangeView->setSceneRect(rangeRect);
ui->rangeView->show();
sMessage.append("Successfully loaded range image");
}else
sMessage.append("Failed to load range image");
*/
qDebug() << sMessage;
}
To copy to clipboard, switch view to plain text mode
I'd appreciate anyone who can spot why I'm getting a SIGSEV error on this and thank you in advance.
Bookmarks