上篇文章介紹的有點凌亂,下面用乙個簡單例子介紹下介面類的使用。
ui_*.h檔案中自動生成的介面類的使用方法有三種:直接使用、定義新類、派生新類。舉例如下:
現有乙個*.ui檔案生成的ui_*.h檔案如下:
#ifndef ui_hellodialog_h
#define ui_hellodialog_h
class ui_hellodialog
// setupui
void retranslateui(qdialog *hellodialog)
// retranslateui
};namespace ui ;
} // namespace ui
qt_end_namespace
#endif // ui_hellodialog_h
(1)直接使用ui::hellodialog類在主函式中定義物件
main.c
#include "ui_hellodialog.h"
int main(int argc, char *argv)
(2)定義新類,在新類中定義乙個ui::hellodialog的子物件,使用子物件載入該介面。mywidget.h
#ifndef mywidget_h
#define mywidget_h
#include namespace ui
class mywidget : public qwidget
;#endif // mywidget_h
mywidget.cpp 在這裡用子物件載入介面
#include "mywidget.h"
#include "ui_mywidget.h"
#include //鍖呭惈澶存枃浠
mywidget::mywidget(qwidget *parent) :
qwidget(parent),
ui(new ui::mywidget)
mywidget::~mywidget()
main.cpp
int main(int argc, char *argv)
(3)派生新類,繼承ui::hellodialog類hellodialog.h#ifndef hellodialog_h
#define hellodialog_h
#include #include "ui_hellodialog.h"
//不用ui::hellodialog 來定義子物件,因此不再需要前置宣告了
//namespace ui
class hellodialog : public qdialog, public ui::hellodialog
;#endif // hellodialog_h
hellodialog.cpp
#include "hellodialog.h"
#include "ui_hellodialog.h"
hellodialog::hellodialog(qwidget *parent) :
qdialog(parent),
ui::hellodialog()
main.cpp
int main(int argc, char *argv)
以上**經驗證無誤,相同的執行結果,如下:
python介面類 Python中的介面類與抽象類
介面類 物件導向中的繼承有兩種用途 1 可以通過繼承做到 重用,並完成擴充套件 2 介面繼承。所謂的介面繼承就是定義乙個介面類 inte ce,介面類中定義了一些介面 就是函式,但這些函式都沒有具體的實現 子類繼承介面類,並且實現介面中的功能 介面繼承可以使得外部呼叫者無需關心具體的實現細節,可用相...
自動生成 SQL LOADER 的控制檔案
經常會用sql loader來倒資料,因此,編寫各種控制檔案就是個日常工作了,呵呵,這裡提供了乙個方法,可以根據表結構自動生成控制檔案 基於指定的表結構格式化sql loader的控制檔案 set feedback off set verify off drop table select text ...
core檔案自動生成的配置
1 編輯環境配置檔案,讓shell啟動時自動設定ulimit vi etc profile ulimit c unlimited dev null 2 1 2 更改core檔案生成路徑 vi etc sysctl.conf kernel.core uses pid 1 kernel.core pat...