• 8449阅读
  • 6回复

勘误 [复制链接]

上一主题 下一主题
离线chai2010
 

只看楼主 倒序阅读 楼主  发表于: 2008-09-02
— 本帖被 yfx2003 执行加亮操作(2008-09-09) —

404页

  1. void MyWidget::paintEvent(QPaintEvent * /* event */)
  2. {
  3.     QPainter painter(this);
  4.     painter.fillRect(rect().adjusted(20, 20, -20, -20), Qt::red);
  5. #ifdef Q_WS_WIN
  6.     HDC hdc = painter.paintEngine()->getDC();
  7.     Rectangle(hdc, 40, 40, width() - 40, height() - 40);
  8.     painter.paintEngine()->releaseDC();
  9. #endif
  10. }


releaseDC缺少参数,应该改为:

  1. painter.paintEngine()->releaseDC(hdc);


英文电子版好像也是有问题 :)

提交者: chai2010
离线yfx2003

只看该作者 1楼 发表于: 2008-09-06
关于代码段在翻译时并没有处理,因而将与电子版保持一致。

应该是有错误的。

不过,当时专门问了 原作者 ,他们说没有什么错误的……
www.qtcn.org/gpq4/
ajaxref.okajax.com/
离线yfx2003

只看该作者 2楼 发表于: 2008-09-06
可以看看能够运行的 随书代码 就可以确定了。
www.qtcn.org/gpq4/
ajaxref.okajax.com/
离线chai2010

只看该作者 3楼 发表于: 2008-09-08
这只是代码片段,没有可执行的文件。
不过看看头文件就知道了(我的是Qt4.3.3):

  1. class QPaintEngine;
  2. class Q_GUI_EXPORT QPaintDevice                                // device for QPainter
  3. {
  4. public:
  5.     enum PaintDeviceMetric {
  6.         PdmWidth = 1,
  7.         PdmHeight,
  8.         PdmWidthMM,
  9.         PdmHeightMM,
  10.         PdmNumColors,
  11.         PdmDepth,
  12.         PdmDpiX,
  13.         PdmDpiY,
  14.         PdmPhysicalDpiX,
  15.         PdmPhysicalDpiY
  16.     };
  17.     virtual ~QPaintDevice();
  18.     virtual int devType() const;
  19.     bool paintingActive() const;
  20.     virtual QPaintEngine *paintEngine() const = 0;
  21. #if defined(Q_WS_QWS)
  22.     static QWSDisplay *qwsDisplay();
  23. #endif
  24. #ifdef Q_WS_WIN
  25.     virtual HDC getDC() const;
  26.     virtual void releaseDC(HDC hdc) const;
  27. #endif
  28.     int width() const { return metric(PdmWidth); }
  29.     int height() const { return metric(PdmHeight); }
  30.     int widthMM() const { return metric(PdmWidthMM); }
  31.     int heightMM() const { return metric(PdmHeightMM); }
  32.     int logicalDpiX() const { return metric(PdmDpiX); }
  33.     int logicalDpiY() const { return metric(PdmDpiY); }
  34.     int physicalDpiX() const { return metric(PdmPhysicalDpiX); }
  35.     int physicalDpiY() const { return metric(PdmPhysicalDpiY); }
  36.     int numColors() const { return metric(PdmNumColors); }
  37.     int depth() const { return metric(PdmDepth); }
  38. protected:
  39.     QPaintDevice();
  40.     virtual int metric(PaintDeviceMetric metric) const;
  41.     ushort        painters;                        // refcount
  42. private:
  43.     Q_DISABLE_COPY(QPaintDevice)
  44. #if defined(Q_WS_X11) && defined(QT3_SUPPORT)
  45. public:
  46.     QT3_SUPPORT Display *x11Display() const;
  47.     QT3_SUPPORT int x11Screen() const;
  48.     QT3_SUPPORT int x11Depth() const;
  49.     QT3_SUPPORT int x11Cells() const;
  50.     QT3_SUPPORT Qt::HANDLE x11Colormap() const;
  51.     QT3_SUPPORT bool x11DefaultColormap() const;
  52.     QT3_SUPPORT void *x11Visual() const;
  53.     QT3_SUPPORT bool x11DefaultVisual() const;
  54.     static QT3_SUPPORT Display *x11AppDisplay();
  55.     static QT3_SUPPORT int x11AppScreen();
  56.     static QT3_SUPPORT int x11AppDepth(int screen = -1);
  57.     static QT3_SUPPORT int x11AppCells(int screen = -1);
  58.     static QT3_SUPPORT Qt::HANDLE x11AppRootWindow(int screen = -1);
  59.     static QT3_SUPPORT Qt::HANDLE x11AppColormap(int screen = -1);
  60.     static QT3_SUPPORT void *x11AppVisual(int screen = -1);
  61.     static QT3_SUPPORT bool x11AppDefaultColormap(int screen =-1);
  62.     static QT3_SUPPORT bool x11AppDefaultVisual(int screen =-1);
  63.     static QT3_SUPPORT int x11AppDpiX(int screen = -1);
  64.     static QT3_SUPPORT int x11AppDpiY(int screen = -1);
  65.     static QT3_SUPPORT void x11SetAppDpiX(int, int);
  66.     static QT3_SUPPORT void x11SetAppDpiY(int, int);
  67. #endif
  68.     friend class QPainter;
  69.     friend class QFontEngineMac;
  70.     friend class QX11PaintEngine;
  71. };
离线yfx2003

只看该作者 4楼 发表于: 2008-09-09
已经收录!

感谢……
www.qtcn.org/gpq4/
ajaxref.okajax.com/
离线lihaowei2028
只看该作者 5楼 发表于: 2008-11-10
本书94页 Plotter实例程序的实现文件中 没有包含头文件
#include  <QtGui>
#include  "plotter.h"
离线yfx2003

只看该作者 6楼 发表于: 2008-11-10
这些都是代码的错误……

原书作者说没有什么错误的,呵呵,结果是。。。
www.qtcn.org/gpq4/
ajaxref.okajax.com/
快速回复
限100 字节
 
上一个 下一个