标题:QDeclarativeView 继承问题
作者:snfx
日期:2011-05-10 22:01
内容:
下面自定义类继承了QDeclarativeView 。不知道为什么就是无法实例化,默认的构造函数没有被执行
但将QDeclarativeView 父类换成QObject 就正常
CWindowFrame.h
#include
class CWindowFrame : public QDeclarativeView
{
Q_OBJECT
public:
explicit CWindowFrame(QWidget *parent = 0);
};
CWindowFrame.cpp
CWindowFrame::CWindowFrame(QWidget *parent,Qt::WindowFlags flags)
: QDeclarativeView(parent)
{
void main()
{
CWindowFrame* cf = new CWindowFrame(NULL); 卡在这。然后就提示崩溃信息。
}
请高手指点~ 是QML工程的
#1 [wxj120bw 05-10 22:27]
这个错误是编译出错的吗 出错的提示是什么?
#2 [snfx 05-10 22:36]
提示这个错误· 压根就没具体提示原因。里面所指的文件只是记录了相关DLL版本信息。然后问是否要发给微软
#3 [cutemmll 05-10 23:00]
你可以在debug模式下运行程序,看一下程序到底是Crash在哪个地方。
还有下面这段代码的main函数貌似不对,是你故意简写成这样的么?
void main()
{
CWindowFrame* cf = new CWindowFrame(NULL); 卡在这。然后就提示崩溃信息。
}
#4 [snfx 05-10 23:22]
main函数不是重点~我随便打的。
重点是 CWindowFrame* cf = new CWindowFrame(NULL);无法通过。
DEBUG跟踪到QTGUI的汇编码出来,看不懂。
用的是VS2010 SP1 + QT 4.7.2 的环境
#5 [cutemmll 05-11 18:51]
我工程是没有问题的。
pro文件
#注意下面这一行中的declarative
QT += core gui declarative
TARGET = testinner
TEMPLATE = app
SOURCES += main.cpp\
cwindowframe.cpp
HEADERS+= cwindowframe.h
头文件
#include
#include //注意头文件
class CWindowFrame : public QDeclarativeView
{
Q_OBJECT
public:
explicit CWindowFrame(QWidget *parent = 0);
~CWindowFrame();
private:
};
cpp
#include "cwindowframe.h"
CWindowFrame::CWindowFrame(QWidget *parent) :
QDeclarativeView(parent)
{
}
CWindowFrame::~CWindowFrame()
{
}
请确认你的pro文件以及头文件是否于上面的代码保持一致。
我的环境是 vs2008 + qt 4.7.1