src/relpipe-out-chart.cpp
branchv_0
changeset 20 b13e7ed9eea3
parent 19 ac70c7af6a9b
child 28 04f1ac8a931b
--- a/src/relpipe-out-chart.cpp	Sun Sep 30 18:34:34 2018 +0200
+++ b/src/relpipe-out-chart.cpp	Sun Sep 30 20:54:35 2018 +0200
@@ -15,6 +15,11 @@
 using namespace relpipe::cli;
 using namespace relpipe::reader;
 
+// signal/slot parameters must be declared here and registered with qRegisterMetaType()
+
+Q_DECLARE_METATYPE(string_t)
+Q_DECLARE_METATYPE(std::vector<AttributeMetadata>)
+
 class RelationalReaderThread : public QThread {
 private:
 	std::shared_ptr<RelationalReader> reader;
@@ -48,13 +53,23 @@
 	RelpipeChartMainWindow window;
 	window.show();
 
-	QtRelationalReaderStringHadler handler(&app, &window);
+	RelationalReaderThread t(reader);
+
+	// Proxy that passes calls from the background thread to the GUI thread using signal-slot mechanism:
+	QtRelationalReaderStringHadler handler(&t); // &t instead of handler.moveToThread(&t); // QObject::moveToThread: Cannot move objects with a parent
+
+	// see Q_DECLARE_METATYPE above
+	qRegisterMetaType<string_t>();
+	qRegisterMetaType<std::vector < AttributeMetadata >> ();
+
+	QObject::connect(&handler, &QtRelationalReaderStringHadler::startRelationReceived, &window, &RelpipeChartMainWindow::startRelation, Qt::ConnectionType::QueuedConnection);
+	QObject::connect(&handler, &QtRelationalReaderStringHadler::attributeReceived, &window, &RelpipeChartMainWindow::attribute, Qt::ConnectionType::QueuedConnection);
+	QObject::connect(&handler, &QtRelationalReaderStringHadler::endOfPipeReceived, &window, &RelpipeChartMainWindow::endOfPipe, Qt::ConnectionType::QueuedConnection);
+
 	reader->addHandler(&handler);
 
 	// Start background thread
-	RelationalReaderThread t(reader);
 	t.start();
-	// ---
 
 	int qtResultCode = app.exec();