So, there is a library on the Internet to handle bitmap files: "bitmap_image.hpp". It seems nice and it works well for my project, until when I try to include "Windows.h" in my project as well. The compiler can't identify both the "bitmap_image" class and "POINT" structure which come from "bitmap_image.hpp" and "Windows.h" respectively.
I tried everything I know but the problem is still not solved. Also, when try to compile another project which includes ONLY cstdio, bitmap_image.hpp and Windows.h, it works.
I uses Qt and here are all the code:
main.cpp
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QtDebug>
#include "bitmap_image.hpp"
#include <Windows.h>
using namespace std;
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
double compare_bitmap(bitmap_image& large, bitmap_image& small, unsigned int top_left_x, unsigned int top_left_y)
{
/*
Purpose:
compare two bitmaps and return the percentage of matched pixels
Description:
this function concerns the pixels in "large" only if it falls in this square--
top-left: (top_left_x, top_left_y)
bottom-right: (top_left_x+small.width()-1, top_left_y+small.height()-1)
while all pixels in "small" will be concerned
Rules:
"large" should not be smaller than "small" in either dimensions
top_left_x should be ranged from 0 to (large.width()-small.width())
top_left_y should be ranged from 0 to (large.height()-small.height())
*/
if(large.width()<small.width() || large.height()<small.height()) return -1;
if(top_left_x<0 || top_left_x>(large.width()-small.width()) || top_left_y<0 || top_left_y>(large.height()-small.height())) return -2;
double pixel_count = 0;
double matched_count = 0;
for(unsigned int y=0; y<small.height(); ++y)
{
for(unsigned int x=0; x<small.width(); ++x)
{
if(large.get_pixel(top_left_x+x, top_left_y+y)==small.get_pixel(x,y)) ++matched_count;
++pixel_count;
}
}
return matched_count/pixel_count;
}
bool identify_bitmap(bitmap_image& large, bitmap_image& small, POINT& result_point, double min_match_percent = 1.0)
{
if(large.width()<small.width() || large.height()<small.height()) return false;
unsigned int p_x, p_y;
double match_percent = 0;
for(unsigned int y=0; y<(large.height()-small.height()+1); ++y)
{
for(unsigned int x=0; x<(large.width()-small.width()+1); ++x)
{
double percent = compare_bitmap(large, small, x, y);
if(percent>match_percent)
{
p_x = x;
p_y = y;
match_percent = percent;
}
}
}
if(match_percent<min_match_percent) return false;
result_point.x = p_x;
result_point.y = p_y;
return true;
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
string s = "capture_2.bmp";
bitmap_image image(s);
if(!image) qDebug()<<"failed";
else qDebug()<<"succeed";
}
MainWindow::~MainWindow()
{
delete ui;
}
Update: I just find the solution for myself. Sorry for the post.
Solution: The first post to this thread stated that we can #define WIN32_LEAN_AND_MEAN just prior to #include <Windows.h>
Although I don't fully understand the reasons...
Related
Using QTCreator, I created the design of a GUI Application. I want to read the input entered by the user from lineEdit and when pushButton is clicked, it should print the factorial of that entered number on the same page. I've read some tutorials but don't understand how to code this using qtc++.
A minimal example is like that:
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QWidget>
#include <QLineEdit>
#include <QPushButton>
#include <QHBoxLayout>
class MainWindow : public QWidget
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
private slots:
void hClicked();
void hTextEdit(const QString& data);
private:
QString m_linedata;
QPushButton button;
QLineEdit lineEdit;
QHBoxLayout layout;
};
#endif // MAINWINDOW_H
mainwindow.cpp
#include "mainwindow.h"
#include <iostream>
MainWindow::MainWindow(QWidget *parent)
: QWidget(parent)
{
layout.addWidget(&lineEdit);
layout.addWidget(&button);
this->setLayout(&layout);
connect(&lineEdit, &QLineEdit::textChanged, this, &MainWindow::hTextEdit);
connect(&button, &QPushButton::clicked, this , &MainWindow::hClicked);
}
MainWindow::~MainWindow()
{
}
static unsigned factorial(unsigned n)
{
unsigned result = 1;
for (unsigned i=1; i <= n; i++) {
result *= i;
}
return result;
}
void MainWindow::hClicked()
{
if (m_linedata.size() > 0) {
bool res ;
int toint = m_linedata.toInt(&res);
if (res) {
unsigned fact_result = factorial(toint);
lineEdit.clear();
lineEdit.setText(QString::number(fact_result)); }
}
}
void MainWindow::hTextEdit(const QString &data)
{
m_linedata = data;
}
and main.cpp
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
Just do anything you like with the data passed to the auxillary buffer.
This is the plot
And this is the code
.pro
QT += core gui widgets datavisualization
TEMPLATE = app
SOURCES += main.cpp mainwindow.cpp
HEADERS += mainwindow.h
main.cpp
#include "mainwindow.cpp"
#include <QApplication>
int main(int argc, char *argv[]) {
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
class MainWindow : public QMainWindow {
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
};
#endif // MAINWINDOW_H
mainwindow.cpp
#include "mainwindow.h"
#include <QMainWindow>
#include <QtDataVisualization/Q3DBars>
using namespace QtDataVisualization;
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
resize(800,600);
Q3DBars *graph = new Q3DBars;
setCentralWidget(QWidget::createWindowContainer(graph));
graph->scene()->activeCamera()->setCameraPosition(30,30);
graph->setBarSpacing(QSizeF(1,3));
QBar3DSeries *series = new QBar3DSeries;
graph->addSeries(series);
QStringList row_labels{"0", "", "20", "", "40"};
QStringList column_labels{"0", "", "20", "", "40"};
graph->rowAxis()->setRange(0, row_labels.count()-1);
graph->columnAxis()->setRange(0, column_labels.count()-1);
series->dataProxy()->setRowLabels(row_labels);
series->dataProxy()->setColumnLabels(column_labels);
// graph->activeTheme()->setGridEnabled(false);
}
MainWindow::~MainWindow(){}
Now to the question:
Can I have grid lines on vertical walls? I mean vertical lines in the picture, same way as in the floor.
Perhaps not possible with Q3DBars though with Q3DScatter maybe:
#include "mainwindow.h"
#include <Q3DScatter>
using namespace QtDataVisualization;
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
auto chart = new Q3DScatter;
setCentralWidget(QWidget::createWindowContainer(chart));
auto series = new QScatter3DSeries;
chart->addSeries(series);
chart->axisX()->setRange(0,50);
chart->axisY()->setRange(0,50);
chart->axisZ()->setRange(0,50);
chart->setShadowQuality(QAbstract3DGraph::ShadowQualityNone);
auto add_bar = [](int x, int y, int z){
auto bar = new QScatterDataArray;;
while(z-- > 0)
*bar << QVector3D(y, z, x);
return bar;
};
QList<QScatterDataArray*> row;
for(int i = 0; i < 5; i++)
row << add_bar(0, i*10, 20);
foreach (auto bar, row)
series->dataProxy()->addItems(*bar);
}
MainWindow::~MainWindow() {}
This question already has an answer here:
Qt/C++ Convert QString to Decimal
(1 answer)
Closed 8 years ago.
I am trying to make a program that takes 3 user inputs and a calculate button that puts them all into an equation and prints out the answer. The problem I am having right now is that the inputs seem to not be able to convert to numbers and I can't figure out why.
Error reads on line (int numN0 = QString::number(N0);):
error: no matching function for call to 'QString::number(QString&)'
Here's my code:
Header
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void on_NtButton_clicked();
void on_N0Button_clicked();
void on_kButton_clicked();
void on_tButton_clicked();
void on_quitButton_clicked();
void on_pushButton_5_clicked();
void on_equation_linkActivated(const QString &link);
private:
Ui::MainWindow *ui;
int N;
int N0;
int k;
int t;
};
Main.cpp
#include "mainwindow.h"
#include <QApplication>
#include <QPushButton>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
/*QPushButton *button = new QPushButton("Quit the program!");
QObject::connect(button, SIGNAL(clicked()), &app, SLOT(quit()));
button->show();
*/
MainWindow w;
w.show();
return a.exec();
}
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QtCore>
#include <QtGui>
#include <QMessageBox>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_N0Button_clicked()
{
QString N0 = ui->lineEdit_2->text();
int numN0 = QString::number(N0);
if (numN0 < 1000){
QMessageBox::information(this,"Error","Can't be over 1000");
}
if (ui->lineEdit_2->text() > 0)
{
QMessageBox::information(this,"Error","Can't be under 0");
}
}
void MainWindow::on_kButton_clicked()
{
int k = ui->lineEdit_3->text();
if (QString::number(k) > 1)
{
QMessageBox::information(this,"Error","Can't be over 1");
}
if (ui->lineEdit_3->text() < 0)
{
QMessageBox::information(this,"Error","Can't be under 0");
}
}
void MainWindow::on_tButton_clicked()
{
QString t = ui->lineEdit_4->text();
}
void MainWindow::on_pushButton_5_clicked()
{
for (int x = 0; x < t; x++)
{
int ans = N*x == N0*10^(k*x);
ui->equation->setText(QString::number(ans));
}
}
You should use:
QString N0 = ui->lineEdit_2->text();
int numN0 = N0.toInt();
QString::number(N0) takes int and return QString, but you need conversion to int. Also you can use bool ok if you want to know is conversion was successful.
For example:
QString str = "FF";
bool ok;
int hex = str.toInt(&ok, 16); // hex == 255, ok == true
int dec = str.toInt(&ok, 10); // dec == 0, ok == false
Information
I am using Qt GUI to track the motion of a sensor. The mainwindow.cpp file is:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "ATC3DG.h"
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>
#include "QTimer"
#include "qtimer.h"
#include "math.h"
double square(double x)
{
return x*x;
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_start_clicked()
{
points.clear(); //points is a global std::vector<cv::Point3> declared in mainwindow.h
errorCode = InitializeBIRDSystem();
errorCode = GetBIRDSystemConfiguration(&ATC3DG.m_config);
id = 0;
errorCode = SetSystemParameter(SELECT_TRANSMITTER, &id, sizeof(id));
EM_time = new QTimer(this);
connect(EM_time, SIGNAL(timeout()), this, SLOT(showValues()));
EM_time->start();
}
void MainWindow::showValues()
{
EM_time->stop();
pRecord = &record;
{
sensorID = 0;
{
errorCode = GetAsynchronousRecord(sensorID, pRecord, sizeof(record));
unsigned int status = GetSensorStatus(sensorID);
if ( status == VALID_STATUS )
{
points.push_back(cv::Point3f(record.x, record.y, record.z));
QString str;
str.sprintf("%f, %f, %f",record.x, record.y, record.z );
this->ui->label->setText(str);
}
}
}
EM_time->start();
}
void MainWindow::on_stop_clicked()
{
EM_time->stop();
double sum = 0;
double dist;
QString str;
for (int i=0; i<points.size()-1; i++)
{
dist = sqrt(square(points[i].x - points[i+1].x) + square(points[i].y - points[i+1].y) + square(points[i].z - points[i+1].z));
sum = sum+dist;
}
str.sprintf("%d cm", sum*2.54);
this->ui->distance->setText(str);
}
ATC3DG.h is the header file of the sensor. record.x, record.y, record.z gives the 3D location of x, y and z location of the sensor in inches. Basically what I am doing is, when I click the start button, the sensor is switched on and the QTimer starts with its signal emitted during timeouts and the showvalues() function will start to execute. This function displays the position of the sensor in label of the Qt GUI. During this loop, points will be filled with all the position values of the sensor.
The stop button stops the timer and calculates the distance using all the points containing in the points vector. This is done using:
double sum=0;
double dist;
for (int i=0; i<points.size()-1; i++)
{
dist = sqrt(square(points[i].x - points[i+1].x) + square((int)points[i].y - (int)points[i+1].y) + square(points[i].z - points[i+1].z));
sum = sum+dist;
}
The sum is giving me totally weird values. For example, when the sensor has moved only about 5 or 6 inches, it is showing values in the range of 100s and like that.
My mainwindow.h file is:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include "ATC3DG.h"
#include "QTimer"
#include <opencv2/core/core.hpp>
namespace Ui {
class MainWindow;
}
class CSystem
{
public:
SYSTEM_CONFIGURATION m_config;
};
class CSensor
{
public: SENSOR_CONFIGURATION m_config;
};
class CXmtr
{
public: TRANSMITTER_CONFIGURATION m_config;
};
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
public slots:
void on_start_clicked();
void showValues();
void on_stop_clicked();
private:
Ui::MainWindow *ui;
private:
DOUBLE_POSITION_ANGLES_RECORD record, *pRecord;
CSystem ATC3DG;
CSensor *pSensor;
CXmtr *pXmtr;
int errorCode;
int sensorID;
int i;
short id;
QTimer *EM_time;
std::vector<cv::Point3f> points;
};
#endif // MAINWINDOW_H
issues I can see in your code:
overuse of braces (they do nothing) - this looks strange and may led to errors
GetAsynchronousRecord suggest asynchronous action and you are using value immediately! I don't known this library but this looks suspicious.
start and stop timer in same method.
you are calculating sum of distances from probably very noisy data. This means that when you do not move sensor over a time you are calculating sum of noise and as a result you have large distance when sensor is not moved at all. You have to filter data before calculating such distance (the easiest is low pass filter).
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).