www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - D --> C++ --> D

reply MGW <mgw yandex.ru> writes:
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;
}

------------------
Mar 31 2016
parent MGW <mgw yandex.ru> writes:
On Thursday, 31 March 2016 at 11:47:34 UTC, MGW wrote:
 ------------------
Help me to optimize this source code. How to apply here delegates and generally whether possibly to make it here
Mar 31 2016