2

如何让 qDebug 打印我的班级是否存在,或有关该班级的信息?不敢相信网上什么都没有。我需要确保 myink = 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 做了一些事情,所以我将发布 ink 的代码

调用它的代码是这样的:

标题: InkSpot *ink;

void InkPuppet::testButton()
{
    ink = new InkSpot(this);
    qDebug() << ink->widget;
    ui->testButton->setText("working");
}

墨点.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_H

墨点.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;
}
4

1 回答 1

4

你想做的事不是微不足道的。qDebug() 显示了一些有用的东西,你必须实现'operator<<'。以下是一个粗略的示例,它可能看起来像这样:

QDebug inline operator<<(QDebug d, const  InkSpot &f){
        QDebug nsp = d.nospace();
        nsp << f.label->text();
        nsp << "\n";
        return d;
}

这将打印您的 InkSpot 的标签文本。添加您需要的任何其他信息。将上述代码放在您的 InkSpot.h 文件中,但在类定义之外。如果您需要访问 InkSpots 的私有数据,您必须让 QDebug operator<< 成为 InkSpot 的朋友。

于 2013-08-27T22:18:23.297 回答