-
Notifications
You must be signed in to change notification settings - Fork 17
#define KE_PROPERTY_MEMBER(type, name) \
private: type m_##name; \
public: Q_PROPERTY(type name MEMBER m_##name) \
const type& Get##name() const { return m_##name; } \
void Set##name(const type& v) { setProperty(#name, QVariant::fromValue<type>(v)); }在父类窗口中记录该对话框对象的指针, 为了回收方便, 可直接定义为 QPointer<QDialog>.
然后在弹出对话框的地方, 对该指针进行判断, 不存在, 则 new 一个出来, 如存在, 则 show().
// .h
QPointer<QDialog> m_dialog;
// .cpp
if (m_dialog.isNull()) {
m_dialog = new QDialog;
}
m_dialog.show();答: 这调用了QPainter的构造方法, 并声明了一个局部的painter对象, 构造方法将会调用begin(),并在析构的时候自动调用end().
所以:
QPainter painter(this);
painter.drawLine(...);相当于:
QPainter painter;
painter.begin(this);
painter.drawLine(...);
painter.end();我们知道对于 QMainWindow 来说, 很自然的重载 closeEvent 即可, 但对于 QDialog 来说, 重载这个却并无法捕捉, "x" 的点击, close 按钮的点击事件.
对于 QDialog, 需要重载 reject. 虽然有点怪怪的, 但无论是右上角的 "x", 还是 close 按钮事件, 都会在这个 reject 槽函数中被捕捉.
You should do like that:
// 为button在group里面编上号。
buttonGroup->setId(button1,1);
// 然后就可以通过id找到button了
buttonGroup->button(1)->setChecked(true);
// 也可以找到当前被check的那个按钮的id
buttonGroup->checkedId();more:
一般会下列错误:
Could Not Run
Unknown debugger type "No engine"
Unable to create a debugger engine of the type "No engine"查看 Tools -> Options -> Build & Run 中, 也会发现 Desktop Qt xxx MSCVxxxx xbit 前面有黄叹号标识.
这原因是因为针对 MSVC 的 Debugger 没有自动检测到. 需要手动安装. 在 https://developer.microsoft.com/en-US/windows/downloads/windows-10-sdk 下载那个 exe.
然后仅选择安装 Debugger 即可. 安装完成后, Desktop Qt xxx MSCVxxxx xbit 就会自动加载检测到的 Debugger, 请注意 x86 与 x64 不同路径的问题即可.
通常我们会用到 Library 里的类与接口,只要确保该类或接口正确导出,则可以正常使用了。但有时,我们会因为历史原因,使用到另一个 Library 里的资源文件。 那么如何保证可以正确编译链接呢?
QLibrary libResource("console"); // use console's resource.
if (!libResource.load())
return -1;加上以上这段语句即可。