我一直在处理我的UI,所有这些东西编译得很好,但我也编写了我的大部分代码,然后为其部分生成了头文件。但是这个头文件不会编译 - 没有错误。它根本就不在构建目录中。
ink.h
#ifndef INK_H
#define INK_H
#include <QPaintDevice>
namespace Ui {
class Ink;
}
class Ink : public QPaintDevice
{
public:
explicit Ink(QWidget *parent = 0);
~Ink();
private:
Ui::Ink *ui;
};
#endif // INK_H
ink.cpp
#include "ink.h"
#include <QtCore>
#include <QtGui>
#include <QWidget>
#include <QPainter>
#include <QPaintEvent>
void ink()
{
QFile *brushInput; //takes raw 8 bit grayscale image, 8 bit values only
char *brushProto;
uchar *brushData;
brushInput = new QFile("x:\\Development\\InkPuppet\\brush.raw"); //open the raw file
brushInput->open(QIODevice::ReadOnly);
QDataStream in;
in.setDevice(brushInput);
int size = brushInput->size(); //set size to length of raw file
brushProto = new char[size];
in.readRawData(brushProto, size); //read file into prototype
brushData = new uchar[size];
for(int i = 0; i < size; ++i)
{
brushData[i] = (uchar)brushProto[i]; //copy char to uchar array
}
QImage test(brushData, 128, 128, QImage::Format_Indexed8);
QImage test2(128, 128, QImage::Format_ARGB32);
QVector<QRgb> vectorColors(256); //create color table
for(int c = 0; c < 256; c++)
{
vectorColors[c] = qRgb(c, c, c);
}
test.setColorTable(vectorColors);
for(int iX = 0; iX < 100; ++iX)
{
for(int iY = 0; iY < 100; ++iY)
{
test2.setPixel(iX, iY, qRgba(255 - (qrand() % 100), 0 + (qrand() % 100), 0 + (qrand() % 100), qAbs((int)test.pixel(iX, iY)-255)));
}
}
//final conversion for stencil and color brush
QPixmap testPixmap = QPixmap::fromImage(test2);
QPixmap testPixmap2 = QPixmap::fromImage(test);
QPainter painter(this);
painter.drawPixmap(150, 50, 100, 100, testPixmap);
painter.drawPixmap(50, 50, 100, 100, testPixmap2);
delete[] brushProto;
delete[] brushData;
delete brushInput;
}
的main.cpp
#include "inkpuppet.h"
#include "ink.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
InkPuppet w;
w.show();
return a.exec();
}
答案 0 :(得分:2)
在QT创建者中创建新表单时,必须选择Qt Designer Form Class才能生成相应的.cpp和.h文件,否则只会生成.ui。