qt - Problems between C++ and qml -
qt - Problems between C++ and qml -
i'm building app using qt quick controls , need c++ in there (for printing , reading file). dug this, i've modified needs:
bonuri.h
#ifndef bonuri_h #define bonuri_h #include <qobject> #include <qtemporaryfile> #include <qiodevice> #include <qpainter> #include <qtsvg/qsvgrenderer> #include <qfile> #include <qtextstream> #include <qtprintsupport/qprintpreviewdialog> #include <qtprintsupport/qprinter> class bonuri : public qobject { q_object public: explicit bonuri(qobject *parent = 0); public slots: void printsvg(const qstring& in); qstring list(); void actualprint(qprinter* p, const qstring& in); }; #endif // bonuri_h bonuri.cpp
#include "bonuri.h" bonuri::bonuri(qobject *parent) : qobject(parent) { } void bonuri::printsvg(const qstring& in){ qprinter printer(qprinter::highresolution); printer.setpapersize(qprinter::a5); qprintpreviewdialog printdialog(&printer); connect(&printdialog, signal(paintrequested(qprinter*)), slot(actualprint(qprinter*, in))); printdialog.exec(); } void actualprint(qprinter* p, const qstring& in){ qtemporaryfile file; if (file.open()){ qtextstream out(&file); out << in; qsvgrenderer renderer(file.filename()); qpainter mypainter(p); mypainter.setrenderhints(qpainter::antialiasing | qpainter::textantialiasing | qpainter::smoothpixmaptransform); renderer.render(&mypainter); } } qstring list(){ qfile file("bonuri.json"); qstring totalline; if(file.open(qiodevice::readonly | qiodevice::text)){ qtextstream in(&file); while (!in.atend()){ qstring line = in.readline(); totalline += line; } } homecoming totalline; } the problem i'm not big of c++ expert , wasn't able debug this.
the problem: moc_bonuri.cpp
undefined reference 'bonuri::list()'; undefined reference 'bonuri::actualprint(qprinter*, qstring const&)'
one more thing: help me optimize code (i'm new c++ , have no thought why way is, used example).
should be:
void bonuri::actualprint(qprinter* p, const qstring& in){ //qtemporaryfile file;//now class fellow member if (file.open()){ qtextstream out(&file); out << in; qsvgrenderer renderer(file.filename()); qpainter mypainter(p); mypainter.setrenderhints(qpainter::antialiasing | qpainter::textantialiasing | qpainter::smoothpixmaptransform); renderer.render(&mypainter); } } qstring bonuri::list(){ qfile file("bonuri.json"); qstring totalline; if(file.open(qiodevice::readonly | qiodevice::text)){ qtextstream in(&file); while (!in.atend()){ qstring line = in.readline(); totalline += line; } } homecoming totalline; } another problem:
connect(&printdialog, signal(paintrequested(qprinter*)), slot(actualprint(qprinter*, in))); you can't utilize more arguments signal has, can utilize less not more. should @ least:
connect(&printdialog, signal(paintrequested(qprinter*)), slot(actualprint(qprinter*))); but in case should totally rewrite method.
class bonuri : public qobject { q_object private: qtemporaryfile file;//... c++ qt
Comments
Post a Comment