如何使qDebug打印我的类是否存在,或有关该类的信息??真不敢相信互联网上什么都没有。我需要确保我的ink = new InkSpot(this;)实际上是返回一些有效的东西。
ink = new InkSpot(this);
qDebug << ink;X:\Development\InkPuppet\inkpuppet.cpp:70: error: C3867: 'QMessageLogger::debug': function call missing argument list; use '&QMessageLogger::debug' to create a pointer to member
我尝试过使用QMessageLogger,但只得到了各种错误。
我的程序崩溃了,因为我对ink.widget做了一些事情,所以我会发布墨迹的代码
调用它的代码如下:
标题:InkSpot *ink;
void InkPuppet::testButton()
{
ink = new InkSpot(this);
qDebug() << ink->widget;
ui->testButton->setText("working");
}inkspot.h
#ifndef INKSPOT_H
#define INKSPOT_H
#include <QObject>
#include <QWidget>
#include <QPainter>
#include <QPaintEvent>
#include <QLabel>
namespace Ui {
class InkSpot;
}
class InkSpot : public QWidget
{
Q_OBJECT
public:
explicit InkSpot(QWidget *parent = 0);
void draw(QPainter *painter);
QWidget *widget;
QLabel *label;
signals:
public slots:
protected:
void paintEvent(QPaintEvent *event);
private:
Ui::InkSpot *ui;
};
#endif // INKSPOT_Hinkspot.cpp
#include "inkspot.h"
#include "inkpuppet.h"
#include "ui_inkpuppet.h"
#include <QtCore>
#include <QtGui>
#include <QWidget>
#include <QPainter>
#include <QPaintEvent>
InkSpot::InkSpot(QWidget *parent) :
QWidget(parent)
{
}
void InkSpot::paintEvent(QPaintEvent *event)
{
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;
}发布于 2013-08-27 22:18:23
你想做的事可不是小事。qDebug()显示了一些有用的东西,您必须实现‘操作符<<’。下面是一个粗略的例子,这可能是什么样子:
QDebug inline operator<<(QDebug d, const InkSpot &f){
QDebug nsp = d.nospace();
nsp << f.label->text();
nsp << "\n";
return d;
}这会打印你的墨迹标签文本。添加您需要的任何其他信息。将上面的代码放在您的InkSpot.h文件中,但放在类定义之外。如果您需要访问InkSpots私有数据,则必须使QDebug operator<<成为InkSpot的朋友。
https://stackoverflow.com/questions/18475913
复制相似问题