D --> C++ --> D

MGW via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Mar 31 04:47:34 PDT 2016


I for myself write Qt-5 wrapper. I use calls from Qt (C ++) as 
extern (C) calls.
Prompt how to write this code well and with use of abilities to 
integrate D and C ++
------------------
// ex4.d - Concepts of QAction.QtE5
// -------- compile ---------
// dmd ex4 qte5

import core.runtime;
import qte5;			// wrapping Qt-5

// (1) handler receives the pointer on object of myQWidget.
// (2) and call method in class myQWidget
extern (C) void handler(myQWidget* wd) {
	(*wd).kn1Press();
}

class myQWidget : QWidget {
	this() {
		// Create widget and set size
		super(this); resize(200, 100);
		// Create button for demo signal -- slot
		// button generates to us a signal
		auto kn1 = new QPushButton("Press me ...", this);
		
		// Create QAction for processings of the slot
		auto actSlot1 = new QAction(this, &handler, aThis);
		// We connect a signal to slots standard means
		connects(kn1, "clicked()", actSlot1, "Slot()");
	}
	// (2) to process clicking of the button
	void kn1Press() {
		msgbox("pressed key on the form");
	}
}

int main(string[] args) {
	// Load library QtE5
	if (1 == LoadQt(dll.QtE5Widgets, true)) return 1;
	// Create app
	QApplication app = new QApplication(&Runtime.cArgs.argc, 
Runtime.cArgs.argv, 1);
	// (1) Create obj of myQWidget and to save this address in obj
	myQWidget mywid = new myQWidget(); mywid.saveThis(&mywid).show;
	app.exec();
	return 0;
}

------------------


More information about the Digitalmars-d-learn mailing list