QT-MSVC error C2248 - c++

I'm currently working on a gui using QT and MSVC 13 compiler.
Whilst setting up a grid I have an error with QWidget
C:\Users\Gaz\Documents\CS22510\simsquare.h:15: error: C2248: 'QWidget::operator =' : cannot access private member declared in class 'QWidget'
in the header file
#ifndef SIMSQUARE_H
#define SIMSQUARE_H
#include <QWidget>
class SimSquare : public QWidget
{
Q_OBJECT
public:
SimSquare(QWidget *parent = 0);
~SimSquare();
protected:
void PaintEvent(QPaintEvent *);
};
#endif // SIMSQUARE_H
this is the cpp file
#include "simsquare.h"
#include <QtGui>
SimSquare::SimSquare(QWidget *parent) : QWidget(parent)
{
QPalette palette(Square::palette());
palette.setColor(Qt::white);
setPalette(palette);
}
void SimSqaure::PaintEvent(QPaintEvent *){
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
painter.setBrush(Qt::white, Qt::SolidPattern);
painter.drawRect(10,15,80,90);
}
SimSquare::~SimSquare()
{
}
and this is referenced in
#include "simulation.h"
#include "ui_simulation.h"
#include <QVector>
Simulation::Simulation(QWidget *parent) : QMainWindow(parent),
ui(new Ui::Simulation)
{
simLayout = new SimBoard(this, 8);
square = new SimSquare(this);
for(int x =0; x<8; x++){
for(int y =0; y<8; y++){
//square = new SimSquare();
squaresVec.append(&square);
simLayout->add_widget(&square);
}
}
this->setLayout(simLayout);
ui->setupUi(this);
}
Simulation::~Simulation()
{
delete ui;
}
Thank you for any help that you may be able to give.

Okay solved that problem,
#include "simulation.h"
#include "ui_simulation.h"
#include "simsquare.cpp"
#include "simboard.cpp"
#include <QVector>
#include <QDebug>
Simulation::Simulation(QWidget *parent) : QMainWindow(parent),
simui(new Ui::Simulation)
{
setupUI();
this->show();
}
void Simulation::setupUI(){
SimBoard simLayout(this,8);
for(int x =0; x<8; x++){
for(int y =0; y<8; y++){
SimSquare square(this);
squaresVec.append(&square);
simLayout.add_widget(&square);
}
}
this->setLayout(&simLayout);
qDebug() << "Setting layout";
simui->setupUi(this);
qDebug() << "setu[ UI";
}
Basically because QWidget can't be copied rather than initialising it using = new, you create the object in the header file and then in the cpp call the constructor using Constructor objectname(parameters).
Just incase anyone else is having this problem.

Related

Qt 6.3 live play not working properly with YUY2

I can't get the qt preview pane to work. It's always black after I plug in the camera.
INFO:
Mac mini
OS: macOS m1, montery 12.3.1
Platform: Qt 6.3
Port: USB3.0
Img format: YUY2
Code snippets:
main.h:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QGraphicsVideoItem>
#include <QCamera>
#include <QMediaCaptureSession>
#include <QMediaDevices>
#include <QCameraDevice>
#include <QList>
#include <QAudioInput>
#include <QCloseEvent>
#include <QPushButton>
#include <QImageCapture>
#include "opencv2/opencv.hpp"
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
protected:
void showEvent(QShowEvent* event);
void closeEvent(QCloseEvent* event);
private:
Ui::MainWindow *ui;
QGraphicsView* pGraphyView;
QGraphicsScene* pGraphyScene;
QGraphicsVideoItem* pGraphyVideoItem;
QCamera* pCamera;
QMediaCaptureSession captureSession;
QAudioInput* pAudioInput;
QImageCapture* pImageCapture;
cv::Mat srcImage;
cv::Mat dstImage;
};
#endif // MAINWINDOW_H
main.cpp:
#include "mainwindow.h"
#include "ui_mainwindow.h"
//=====================================================================
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
pGraphyView = 0;
pGraphyScene = 0;
pGraphyVideoItem = 0;
pCamera = 0;
}
//=====================================================================
MainWindow::~MainWindow()
{
delete ui;
}
//=====================================================================
void MainWindow::showEvent(QShowEvent* event)
{
pAudioInput = new QAudioInput;
captureSession.setAudioInput(pAudioInput);
QStringList str_list;
QString str_id;
QString str_vid;
QString str_pid;
const QList<QCameraDevice> cameras = QMediaDevices::videoInputs();
qDebug() << "camera count = " << cameras.size();
for (const QCameraDevice &cameraDevice : cameras)
{
str_id = cameraDevice.id();
str_vid = str_id.mid(9,4);
str_pid = str_id.right(4);
qDebug() << "id = " << str_id;
qDebug() << "vid = 0x" << str_vid;
qDebug() << "pid = 0x" << str_pid;
if(str_vid == "a168")
{
pCamera = new QCamera(cameraDevice);
captureSession.setCamera(pCamera);
pGraphyScene = new QGraphicsScene(0,0,640,480);
pGraphyView = new QGraphicsView(this);
pGraphyView->setScene(pGraphyScene);
this->setCentralWidget((QWidget*)pGraphyView);
pGraphyVideoItem = new QGraphicsVideoItem;
pGraphyVideoItem->setSize(QSizeF(640,480));
pGraphyVideoItem->setPos(0,0);
pGraphyScene->addItem(pGraphyVideoItem);
captureSession.setVideoOutput(pGraphyVideoItem);
pCamera->start(); // live play.
break;
}
}
}
//=====================================================================
void MainWindow::closeEvent(QCloseEvent* event)
{
if(pAudioInput)
{
delete pAudioInput;
pAudioInput = 0;
}
if(pGraphyVideoItem)
{
delete pGraphyVideoItem;
pGraphyVideoItem = 0;
}
if(pGraphyScene)
{
delete pGraphyScene;
pGraphyScene = 0;
}
if(pGraphyView)
{
delete pGraphyView;
pGraphyView = 0;
}
event->accept();
}
I tried using macOS' facetime to check if the camera itself is functionable, and it did. The facetime live play smoothly.
I guess it's something related to Qt 6.3.

Why can't I construct my subclass in QT C++? [duplicate]

This question already has answers here:
What is an undefined reference/unresolved external symbol error and how do I fix it?
(39 answers)
Closed 7 months ago.
I am working on a project that utilizes a whole suite of custom widget that my company uses.
I am trying to subclass the QLineEdit QWidget so that I can override the default arrow key behavior. It should just behave like a regular QLineEdit.
I then want to use this custom QLineEdit (that I named DataLineEdit), in place of the standard QLineEdits that I dynamically created in another Widget, DataWidget.
I have followed tutorial after tutorial on subclassing, but cannot avoid the error:
undefined reference to "DataLineEdit::DataLineEdit(QWidget*)
My code is below.
datalineedit.h
#ifndef DATALINEEDIT_H
#define DATALINEEDIT_H
#include <QLineEdit>
#include <QWidget>
class DataLineEdit: public QLineEdit
{
Q_OBJECT
public:
explicit DataLineEdit(QWidget *parent = 0);
~DataLineEdit();
protected:
void keyPressEvent(QKeyEvent* event);
signals:
void leftRightOverrideKeyPress(int state);
private:
};
#endif // CUSTOMLINEEDIT_H
datalineedit.cpp
#include "datalineedit.h"
#include<QKeyEvent>
DataLineEdit::DataLineEdit(QWidget*parent) : QLineEdit(parent)
{
}
DataLineEdit::~DataLineEdit()
{
}
void DataLineEdit::keyPressEvent(QKeyEvent *event)
{
if(event->key() == Qt::Key_Left && this->cursorPosition() == 0)
{
emit leftRightOverrideKeyPress(0);
}
else if(event->key() == Qt::Key_Right && this->cursorPosition() == 2)
{
emit leftRightOverrideKeyPress(1);
}
else
{
QLineEdit::keyPressEvent(event);
}
}
datawidget.h
#define DATAWIDGET_H
#include <QFile>
#include <QFileDialog>
#include <QTextStream>
#include <QMessageBox>
#include <QLineEdit>
#include <QObject>
#include <QtCore>
#include <QtGui>
#include <QKeyEvent>
#include <QMainWindow>
#include "datalineedit.h"
extern int focusRow;
extern int focusCol;
extern int numRows;
extern int numBottomRowCols;
extern QLineEdit *focusedLineEdit;
namespace Ui{
class DataWidget;
}
class QLineEdit;
class QLabel;
class DataWidget : public QWidget
{
Q_OBJECT
public:
explicit DataWidget(QWidget *parent = 0);
~DataWidget();
QString data;
protected:
bool eventFilter(QObject *object, QEvent *event);
public slots:
void focusChanged(QWidget *old, QWidget *now);
void arrowKeyNavigation(int state);
void on_applyChangePushButton_clicked();
void setData(QString text);
QString getData();
private slots:
void updateDataGridVisibility();
void on_payloadLineEdit_textChanged(const QString &arg1);
void on_savePushButton_clicked();
void on_openPushButton_clicked();
void on_presetComboBox_currentIndexChanged(int index);
private:
Ui::DataWidget *ui;
QString currentFile = "";
};
#endif // DATAWIDGET_H
datawidget.cpp
#include "datawidget.h"
#include "datawidget.h"
#include "datalineedit.h"
#include <QGridLayout>
#include <QLineEdit>
#include <QGroupBox>
#include <QKeyEvent>
#include <QIntValidator>
int focusRow;
int focusCol;
int numRows;
int numBottomRowCols;
QLineEdit *focusedLineEdit;
enum key_directions
{
arrowLeft = 0,
arrowRight = 1,
arrowUp = 2,
arrowDown = 3
};
enum presets
{
preset1 = 0,
preset2 = 1,
preset3 = 2,
preset4 = 3,
preset5 = 4,
clean = 5,
zeroes = 6
};
DataWidget::DataWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::DataWidget)
{
ui->setupUi(this);
this->installEventFilter(this);
connect(qApp, SIGNAL(focusChanged(QWidget*, QWidget*)), this, SLOT(focusChanged(QWidget*,QWidget*)));
//payloadLineEdit
ui->payloadLineEdit->setValidator(new QIntValidator(0,64, this));
ui->payloadLineEdit->setFixedSize(20,20);
ui->payloadLineEdit->setTextMargins(0,0,0,0);
//dataGridLayout
ui->dataGridLayout->setAlignment(Qt::AlignLeft);
ui->dataGridLayout->setAlignment(Qt::AlignTop);
for(int i=0; i<4; i++)
{
for(int j=0; j<16; j++)
{
DataLineEdit *lineEdit = new DataLineEdit();
lineEdit->setText("00");//set data default
lineEdit->setInputMask("Hh");//limit to hex values
lineEdit->setFixedSize(20,20);
lineEdit->setTextMargins(0,0,0,0);
lineEdit->setAlignment(Qt::AlignCenter);
lineEdit->setAlignment(Qt::AlignCenter);
connect(lineEdit, SIGNAL(leftRightOverrideKeyPress(int)), this, SLOT(arrowKeyNavigation(int)));
ui->dataGridLayout->addWidget(lineEdit, i, j);
}
}
updateDataGridVisibility();
}
DataWidget::~DataWidget()
{
delete ui;
}
void DataWidget::arrowKeyNavigation(int state)
{
//does something
}
You could edit the class in the following form:
class DataLineEdit: public QLineEdit
{
Q_OBJECT
public:
explicit DataLineEdit(QWidget* parent = 0);
...
and
DataLineEdit::DataLineEdit(QWidget* parent) : QLineEdit(parent)
{
}
Thank you for all the help, it was definitely a linker issue but since I am working within a much larger project, I didn't want to mess with imports or .pro files too much. DataLineEdit is specific to DataWidget, so I simply moved the entire datalineedit.h file into the datawidget.h file at the bottom, and the same for the .cpp files. This avoids any linking all together and keeps things tidier based on the project's file hierarchy.

Explain how to use pointers?

Sorry, I use google translator.
I am exploring how QGraphicsItem works.
But I don’t understand how the data is transmitted through the pointers to the scene.
Here is a code
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "qmyscene.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
scene = new QMyScene(this);
ui->graphicsView->setScene(scene);
scene->setSceneRect(0,0,800,600);
}
MainWindow::~MainWindow()
{
delete ui;
}
qmyscene.cpp
#include "qmyscene.h"
#include "qpixitem.h"
#include <qdebug.h>
QMyScene::QMyScene(QObject *parent) : QGraphicsScene(parent)
{
QPixItem *pix1 = new QPixItem (this,100,100);
QPixItem *pix2 = new QPixItem (this,50,50);
}
QMyScene::~QMyScene()
{
}
qpixitem.cpp
#include "qpixitem.h"
#include <QMessageBox>
QPixItem::QPixItem (QGraphicsScene *MyScene,int x,int y): QGraphicsPixmapItem()
{
QPixmap pic (":/Items/OutLet.png");
this->setPixmap(pic);
this->setPos(x, y);
this->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemSendsGeometryChanges);
qDebug() << "create";
QGraphicsLineItem* line = MyScene->addLine(QLineF(40, 40, 80, 80));
MyScene->addItem(this);
}
QVariant QPixItem::itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value)
{
if (change == ItemPositionChange)
{
QPointF newPos = value.toPointF();
int p1 = newPos.x();
int p2 = newPos.y();
MyScene->addLine(QLineF(40,40,p1, p2)); //error
//this->line->setLine(QLineF(40,40,p1, p2)); //error
qDebug() << "Scene::move";
}
return QGraphicsItem::itemChange(change, value);
}
qmyscene.h
#ifndef QMYSCENE_H
#define QMYSCENE_H
#include <QGraphicsScene>
#include <QDebug>
class QMyScene: public QGraphicsScene
{
Q_OBJECT
public:
explicit QMyScene(QObject *parent = 0);
~QMyScene();
private:
};
#endif // QMYSCENE_H
qpixitem.h
#ifndef QPIXITEM_H
#define QPIXITEM_H
#include <QGraphicsItem>
#include "QGraphicsScene"
#include "mainwindow.h"
#include <QGraphicsPixmapItem>
class QPixItem: public QGraphicsPixmapItem
{
public:
QPixItem (QGraphicsScene *MyScene,int x,int y);
QGraphicsScene *MyScene;
int x,y;
private:
QGraphicsLineItem* line;
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
};
#endif // QPIXITEM_H
// error - the lines cause an error (closing the program due to memory access), I am sure that this is due to improperly used pointers. How to use them correctly in such code?
You never seem to allocate this->line.
Did you mean:
this->line = MyScene->addLine(QLineF(40, 40, 80, 80));
Instead of
QGraphicsLineItem* line = MyScene->addLine(QLineF(40, 40, 80, 80));

Qt / C++ - "Including" a header file causes a LOT of errors (spam)

I'm having some problems with my script. Everything was fine for a while but now when I #include a file I get errors that occur on any line pointing to another class. Like these (there's actually 12 of them..):
x:\development\inkpuppet\newdialog.h:20: error: C2143: syntax error : missing ';' before '*'
x:\development\inkpuppet\newdialog.h:20: error: C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Occurs when I say InkPuppet *pointerToPuppet;
Edit: the include I can't put in the header is inkspot.h in the inkpuppet.h header.
For each pointer I get the two above errors x3.
Then I get errors because obviously the pointers no longer work.
I'm going to go ahead and post all my code because I do not know which parts will be relevant.
inkpuppet.h
#ifndef INKPUPPET_H
#define INKPUPPET_H
#include "inkspot.h"
//#include "ui_inkpuppet.h"
#include <QMainWindow>
#include <QWidget>
namespace Ui {
class InkPuppet;
}
class InkPuppet : public QMainWindow
{
Q_OBJECT
public:
explicit InkPuppet(QWidget *parent = 0);
~InkPuppet();
Ui::InkPuppet *ui;
private slots:
void setMinimum(int value);
void setMaximum(int value);
void actionNew();
void actionAbout();
void setSpacing(int);
void on_colorAButton_clicked();
};
#endif // INKPUPPET_H
inkpuppet.cpp
#include "inkpuppet.h"
#include "ui_inkpuppet.h"
#include "newdialog.h"
#include "aboutdialog.h"
#include "inkspot.h"
#include <Qt>
#include <QtCore>
#include <QtGui>
#include <QWidget>
#include <QDialog>
#include <QMainWindow>
#include <QDebug>
#include <QColorDialog>
InkPuppet::InkPuppet(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::InkPuppet)
{
ui->setupUi(this);
//connect the frame range boxes to the timeslider
connect(ui->lowerFrameBox, SIGNAL(valueChanged(int)), this, SLOT(setMinimum(int)));
connect(ui->upperFrameBox, SIGNAL(valueChanged(int)), this, SLOT(setMaximum(int)));
//connect tool palette items
connect(ui->spacingBox, SIGNAL(valueChanged(int)), this, SLOT(setSpacing(int)));
connect(ui->colorAButton, SIGNAL(clicked()), this, SLOT(on_colorAButton_clicked()));
//connect the menu items
connect(ui->actionNew, SIGNAL(triggered()), this, SLOT(actionNew()));
connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(actionAbout()));
}
void InkPuppet::setMinimum(int value)
{
ui->timeSlider->setMinimum(value);
ui->frameNumberBox->setMinimum(value);
}
void InkPuppet::setMaximum(int value)
{
ui->timeSlider->setMaximum(value);
ui->frameNumberBox->setMaximum(value);
}
void InkPuppet::setSpacing(int)
{
InkSpot *spot = new InkSpot(this);
//spot->puppet = this;
spot->spacing = ui->spacingBox->value();
}
//menu items
void InkPuppet::actionNew()
{
NewDialog *nDialog = new NewDialog;
//nDialog->createNew(this);
nDialog->pointerToPuppet = this;
nDialog->setModal(true);
nDialog->show();
}
void InkPuppet::actionAbout()
{
AboutDialog *aDialog = new AboutDialog;
aDialog->setModal(true);
aDialog->show();
}
//tool menu
void InkPuppet::on_colorAButton_clicked()
{
// QColor color = QColorDialog(QColor->setRgb(255, 0, 0));
// //color->setRgb(0, 0, 0);
// qDebug() << "done";
// if(color->isValid())
// {
// QString qss = QString("background-color: %1").arg(color->name());
// ui->colorAButton->setStyleSheet(qss);
// }
}
InkPuppet::~InkPuppet()
{
delete ui;
}
inkspot.h
#ifndef INKSPOT_H
#define INKSPOT_H
#include "newdialog.h"
//#include "inkpuppet.h"
#include <QObject>
#include <QWidget>
#include <QPainter>
#include <QPaintEvent>
#include <QLabel>
#include <QPoint>
#include <QImage>
namespace Ui {
class InkSpot;
}
class InkSpot : public QWidget
{
Q_OBJECT
public:
explicit InkSpot(QWidget *parent = 0);
void draw(QPainter *painter);
QWidget *widget;
int canvasWidth;
int canvasHeight;
float spacing;
NewDialog *newDialog;
QPixmap pixmap;
signals:
//int sendWidthOfCanvas();
//void sendHeightOfCanvas();
public slots:
//void widthOfCanvas();
//void heightOfCanvas();
protected:
void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
void paintEvent(QPaintEvent *event);
private:
void drawLineTo(const QPoint &endPoint);
bool drawing;
QPoint lastPoint;
QImage image;
QImage test2;
Ui::InkSpot *ui;
};
#endif // INKSPOT_H
inkspot.cpp
#include "inkspot.h"
#include "inkpuppet.h"
#include "ui_inkpuppet.h"
#include "newdialog.h"
#include "ui_newdialog.h"
#include <QtCore>
#include <QtGui>
#include <QWidget>
#include <QPainter>
#include <QPaintEvent>
InkSpot::InkSpot(QWidget *parent) :
QWidget(parent)
{
widget = this;
drawing = false;
//spacing = puppet->ui->spacingBox->value();
spacing = 1;//puppet->ui->spacingBox->value();
}
void InkSpot::mousePressEvent(QMouseEvent *event)
{
if(event->button() == Qt::LeftButton)
{
lastPoint = event->pos();
drawing = true;
}
}
void InkSpot::mouseMoveEvent(QMouseEvent *event)
{
if((event->buttons() & Qt::LeftButton) && drawing)
{
drawLineTo(event->pos());
}
}
void InkSpot::mouseReleaseEvent(QMouseEvent *event)
{
if(event->button() == Qt::LeftButton && drawing)
{
drawLineTo(event->pos());
drawing = false;
}
}
void InkSpot::drawLineTo(const QPoint &endPoint)
{
QPainter painter(&pixmap);
painter.setPen(Qt::NoPen);
painter.setBrush(Qt::NoBrush);
QFile *stencilInput; // file for input, assumes a SQUARE RAW 8 bit grayscale image, no JPG no GIF, no size/format header, just 8 bit values in the file
char *brushPrototype; // raw brush prototype
uchar *brushData; // raw brush data
stencilInput = new QFile("C:/brush3.raw"); // open raw file
stencilInput->open(QIODevice::ReadOnly);
QDataStream in;
in.setDevice(stencilInput);
int size = stencilInput->size(); // set size to the length of the raw file
brushPrototype = new char[size]; // create the brush prototype array
in.readRawData(brushPrototype, size); // read the file into the prototype
brushData = new uchar[size]; // create the uchar array you need to construct QImage
for (int i = 0; i < size; ++i)
brushData[i] = (uchar)brushPrototype[i]; // copy the char to the uchar array
QImage test(brushData, 128, 128, QImage::Format_Indexed8); // create QImage from the brush data array
// 128x128 was my raw file, for any file size just use the square root of the size variable provided it is SQUARE
QImage test2(128, 128, QImage::Format_ARGB32);
QVector<QRgb> vectorColors(256); // create a color table for the image
for (int c = 0; c < 256; c++)
vectorColors[c] = qRgb(c, c, c);
test.setColorTable(vectorColors); // set the color table to the image
for (int iX = 0; iX < 128; ++iX) // fill all pixels with 255 0 0 (red) with random variations for OIL PAINT effect
// use your color of choice and remove random stuff for solid color
// the fourth parameter of setPixel is the ALPHA, use that to make your brush transparent by multiplying by opacity 0 to 1
{
for (int iY = 0; iY < 128; ++iY)
{
test2.setPixel(iX, iY, qRgba(255, 100, 100, (255-qGray(test.pixel(iX, iY)))*0.5));
}
}
// final convertions of the stencil and color brush
QPixmap testPixmap = QPixmap::fromImage(test2);
QPixmap testPixmap2 = QPixmap::fromImage(test);
painter.setBrush(Qt::NoBrush);
painter.setPen(Qt::NoPen);
// in a paint event you can test out both pixmaps
// QLineF line = QLineF(lastPoint, endPoint);
// float lineLength = line.length();
// qDebug() << line.length();
// line.setLength(100.01f);
// qDebug() << line.length();
QPainterPath path = QPainterPath(lastPoint);
path.lineTo(endPoint);
//qDebug() << path.currentPosition();
//qDebug() << path.length();
qreal length = path.length();
qreal pos = 0;
while (pos < length)
{
qreal percent = path.percentAtLength(pos);
painter.drawPixmap(path.pointAtPercent(percent).x() - 16, path.pointAtPercent(percent).y() - 16, 32, 32, testPixmap);
pos += spacing;
}
//painter.drawPixmap(line.p1().x() - 16, line.p1().y() - 16, 32, 32, testPixmap);
//delete all dynamically allocated objects with no parents
delete [] brushPrototype;
delete [] brushData;
delete stencilInput;
lastPoint = endPoint;
}
void InkSpot::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
painter.setPen(Qt::NoPen);
painter.setBrush(Qt::NoBrush);
QRect rect = event->rect();
painter.drawPixmap(rect, pixmap, rect);
qDebug() << spacing;
update();
}
newdialog.h
#ifndef NEWDIALOG_H
#define NEWDIALOG_H
//#include "ui_newdialog.h"
#include "inkpuppet.h"
#include <QDialog>
namespace Ui {
class NewDialog;
}
class NewDialog : public QDialog
{
Q_OBJECT
public:
explicit NewDialog(QWidget *parent = 0);
~NewDialog();
InkPuppet *pointerToPuppet;
Ui::NewDialog *ui;
public slots:
//void createNew(InkPuppet *existingPuppet);
void createNew();
};
#endif // NEWDIALOG_H
newdialog.cpp
#include "newdialog.h"
#include "ui_newdialog.h"
#include "inkpuppet.h"
#include "ui_inkpuppet.h"
#include "inkspot.h"
#include <QDebug>
#include <QSignalMapper>
#include <QObject>
#include <QtOpenGL/QGLWidget>
NewDialog::NewDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::NewDialog)
{
ui->setupUi(this);
connect(ui->buttonBox, SIGNAL(accepted()), SLOT(createNew()));
//connect(ui->buttonBox, SIGNAL(accepted()), SLOT(createNew(InkPuppet*)));
}
void NewDialog::createNew()
{
InkSpot *ink;
ink = new InkSpot();
ink->newDialog = this;
pointerToPuppet->ui->canvas->addWidget(ink->widget);
//QSize size = pointerToPuppet->ui->canvas->sizeHint();
ink->widget->resize(ui->widthBox->value(), ui->heightBox->value());
pointerToPuppet->ui->scrollCanvasItems->resize(ui->widthBox->value(), ui->heightBox->value());
//pointerToPuppet->ui->canvas->setAlignment(ink->widget, Qt::AlignAbsolute);
ink->pixmap = QPixmap(QSize(ui->widthBox->value(), ui->heightBox->value()));
close();
}
NewDialog::~NewDialog()
{
delete ui;
}
main.cpp
#include "inkpuppet.h"
#include "inkspot.h"
#include "newdialog.h"
#include "aboutdialog.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
InkPuppet w;
w.show();
return a.exec();
}
You have circular dependencies. "inkpuppet.h" includes "inkspot.h", which includes "newdialog.h", which includes "inkpuppet.h". Use forward declarations instead, where you can.
You have circular includes, that are prevented by your header guardians. This means that in your newdialog.h the line #include "inkpuppet.h" does nothing, resulting in the InkPuppet class is not declared. You need to replace the include line by a forward declaration class InkPuppet; and don't forget to include the file in the cpp (in that case, you've got it already).
EDIT: You have to be careful with the namespaces as well, you've got all your classes in two namespaces (global and Ui).

Qt error:expected primary-expression before ')' token

I'm Qt beginner and have a problem:
I'm using QT(4.8.4) with C++ using QTCreator(2,72).
When I attempt to compile the program I get:
expected primary-expression before ')' token on Line 26.
My main.cpp: Part/Section of the program
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFileDialog>
#include "view.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
createActions();
createMenus();
//Fenster für Visualisierung
ui->dockWidget->setWidget(view); //ERROR Line 26
ui->dockWidget->setWindowTitle("Visualisierung");
ui->dockWidget->setGeometry(20,200,300,300);
}
My view.cpp:
#include "view.h"
#include <QtGui>
#include <GL/glu.h>
#include <QtOpenGL/QGLWidget>
extern QVector<QMatrix4x4> T_tracked_Point_Cam;
extern QVector<QMatrix4x4> T_approx_Point_Cam;
// Konstruktor
view::view(QWidget *parent) :
QGLWidget(QGLFormat(QGL::SampleBuffers), parent)
{
xRot = 0;
yRot = 0;
zRot = 0;
zoom = 0;
virtuellerAbstand = 0;
xT = 0;
yT = 0;
trackPoint = false;
laserPoint = false;
laserOrients = false;
gitterPoint = true;
Cam_Koo_Trans_X = 0;
Cam_Koo_Trans_Y = 0;
Cam_Koo_Trans_Z = 0;
}
// Destruktor
view::~view()
{}
main.h:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QDebug>
#include <QMessageBox>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void openDCMFile();
void drawDICOMImg(std::string fileDICOM);
private:
Ui::MainWindow *ui;
void createActions();
void createMenus();
QMenu *fileMenu;
QAction *openAct;
signals:
void AnzeigeGetracktePunkte(bool);
void AnzeigeLaserPunkte(bool);
void AnzeigeLaserOrients(bool);
void AnzeigeGitterPunkte(bool);
void update_view();
};
#endif // MAINWINDOW_H
vieh.h:
#ifndef VIEW_H
#define VIEW_H
#include <QtOpenGL/QGLWidget>
class view : public QGLWidget
{
Q_OBJECT
public:
view(QWidget *parent = 0);
~view();
QSize minimumSizeHint() const;
QSize sizeHint() const;
double x_max, y_max, z_max;
double x_min, y_min, z_min;
void Zeichnen_getrackte_Punkte();
void Zeichnen_Laserpunkte();
void Zeichnen_Laserorients();
signals:
public slots:
....
protected:
.....
private:
.....
};
#endif // VIEW_H
Thanks for the help in advance.
view is just a name of a type. You probably want to pass an instance of it:
ui->dockWidget->setWidget(view());
// ^^