QtE5-在舒适图形中学习D和Qt5环境
QtE5 是D中Qt5 函数绑定(包装器).Qt 是巨大的,QtE5 只是其中很小一部分.是的,我边学习Qt ,边根据需要时绑定,我用D+QtE5 来编写所有Qt项目 .写本文时,QtE5 中约有400 个Qt 函数. QtE5 在(WinXP,7,10)32位 上,(Win7,10)64位 及Linux32/64 上测试和工作. 除非扩展,不需要安装整个Qt .但需要dmd 及Qt5 运行时. QtE5 与Qt 中名称对应.
import qte5;
import core.runtime;
int main(string[] args) {
if (1 == LoadQt(dll.QtE5Widgets, true)) return 1;
QApplication app = new QApplication(&Runtime.cArgs.argc,Runtime.cArgs.argv, 1);
QLabel lb = new QLabel(null);
lb.setText("<h1>哈哈</h1>").show();
app.exec();
return 0;
}
qt 可能不支持gbk .下个示例:
import qte5;
import core.runtime;
import std.stdio;
extern (C) {
void onKn1(CTest* uk) { (*uk).runKn1(); }
void onKn2(CTest* uk) { (*uk).runKn2(); }
void onD(CTest* uk, int n, int ab) { (*uk).D(ab, n); }
}
class CTest : QFrame {
QVBoxLayout vblAll;
QHBoxLayout hb2;
QTextEdit edTextEdit;
QPushButton kn1, kn2;
QAction acKn1, acKn2, acDes1, acDes2;
QLineEdit lineEdit;
QFrame view;
~this() {
}
this(QWidget parent, QtE.WindowType fl) {
super(parent, fl);
vblAll = new QVBoxLayout(null);
hb2 = new QHBoxLayout(null);
edTextEdit = new QTextEdit(this);
vblAll.addWidget(edTextEdit);
lineEdit = new QLineEdit(this);
lineEdit.setNoDelete(true);
lineEdit.setText("大家好");
lineEdit.setReadOnly(true);
view = new QFrame(this);
view.setMinimumHeight(200);
setFrameShape( QFrame.Shape.Box );
view.setFrameShape( QFrame.Shape.Box );
view.setFrameShadow( QFrame.Shadow.Raised );
kn1 = new QPushButton("1按钮", this);
kn2 = new QPushButton("2按钮", this);
acKn1 = new QAction(this, &onKn1, aThis);
connects(kn1, "clicked()", acKn1, "Slot()");
acKn2 = new QAction(this, &onKn2, aThis); connects(kn2, "clicked()", acKn2, "Slot()");
hb2.addWidget(kn1).addWidget(kn2);
vblAll.addWidget(lineEdit).addWidget(view).addLayout(hb2);
resize(700, 500); setWindowTitle("Проверка QTextEdit");
setLayout(vblAll);
}
void D(int ab, int n) {
writeln(n, "--------------------------------D---------------------->", ab);
}
void runKn1() {
writeln("this is Button 1");
QFileDialog fileDlg = new QFileDialog('+', null);
string cmd = fileDlg.getOpenFileNameSt("Open file ...", "", "*.d *.ini *.txt");
if(cmd != "") lineEdit.setText(cmd);
}
void runKn2() {
writeln("this is Button 2");
}
}
int main(string[] args) {
bool fDebug = true; if (1 == LoadQt(dll.QtE5Widgets, fDebug)) return 1;
QApplication app = new QApplication(&Runtime.cArgs.argc, Runtime.cArgs.argv, 1);
CTest ct = new CTest(null, QtE.WindowType.Window); ct.show().saveThis(&ct);
QEndApplication endApp = new QEndApplication('+', app.QtObj);
return app.exec();
}
注意,处理事件程序,必须声明为extern(C) . 注意,连接槽 :
connects(kn1, "clicked()", acKn1, "Slot()");
QtE5 无须Qt元编译器 .可相互连接 . QtE5 很好的补充了D.
|