creating cpp library using qt
-
@jsulm said in creating cpp library using qt:
QT += widgets
can you also help me in writing the main.cpp file..
how to actually call the mainwindow there with the library output in it@amruz You use it as any other library. You're already doing it with Qt.
Just include the header file of your library and use it. For example create an instance of Worksharedlib.#include "sharedlib.h" int main() { ... Worksharedlib lib; lib.show(); ... }
-
@amruz You use it as any other library. You're already doing it with Qt.
Just include the header file of your library and use it. For example create an instance of Worksharedlib.#include "sharedlib.h" int main() { ... Worksharedlib lib; lib.show(); ... }
-
@jsulm said in creating cpp library using qt:
Worksharedlib lib;
lib.show();i used the same way only.. but i am getting error as follows
/home/amruz/worksharedlib/worksharedlib.h:14: error: undefined reference to `vtable for Worksharedlib'
@amruz Will probably not solve that error, but this looks wrong as well:
QT -= gui
Your app is going to show an UI, right? Then it is a gui app:
QT += core gui widgets
Don't forget to rerun qmake after changing pro file and rebuild.
-
@amruz Will probably not solve that error, but this looks wrong as well:
QT -= gui
Your app is going to show an UI, right? Then it is a gui app:
QT += core gui widgets
Don't forget to rerun qmake after changing pro file and rebuild.
-
@jsulm said in creating cpp library using qt:
QT += core gui widgets
this is a console application actually..is that the problem?
@amruz If it is a console application then why do you want to use a library which provides an UI class:
class WORKSHAREDLIBSHARED_EXPORT Worksharedlib:public QWidget { Q_OBJECT public: //Worksharedlib(); Worksharedlib(QWidget *parent = 0); ~Worksharedlib() {} private slots: void handleButton(); void m_buttonClicked(); private: QPushButton *m_button; QLineEdit *m_textbox; QHBoxLayout *layout; QWidget *window; QLabel * label; QWidget *frame; };
?
-
@amruz If it is a console application then why do you want to use a library which provides an UI class:
class WORKSHAREDLIBSHARED_EXPORT Worksharedlib:public QWidget { Q_OBJECT public: //Worksharedlib(); Worksharedlib(QWidget *parent = 0); ~Worksharedlib() {} private slots: void handleButton(); void m_buttonClicked(); private: QPushButton *m_button; QLineEdit *m_textbox; QHBoxLayout *layout; QWidget *window; QLabel * label; QWidget *frame; };
?
-
@amruz Yes. You're using widgets - so it must be a gui application with widgets, right?
QT += core gui widgets
@jsulm when i try to include this library in a widget application also i am getting the same error..
this is the .pro file of my widgetapplication
#------------------------------------------------- # # Project created by QtCreator 2017-07-27T17:19:21 # #------------------------------------------------- QT += core gui widgets greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = sharedlibtryinwidget TEMPLATE = app SOURCES += main.cpp\ mainwindow.cpp HEADERS += mainwindow.h DEPENDPATH += /home/amruz/worksharedlib INCLUDEPATH += /home/amruz/worksharedlib LIBS += -L/home/amruz/build-worksharedlib-Desktop_Qt_5_7_0_GCC_64bit-Debug -lworksharedlib
-
@jsulm when i try to include this library in a widget application also i am getting the same error..
this is the .pro file of my widgetapplication
#------------------------------------------------- # # Project created by QtCreator 2017-07-27T17:19:21 # #------------------------------------------------- QT += core gui widgets greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = sharedlibtryinwidget TEMPLATE = app SOURCES += main.cpp\ mainwindow.cpp HEADERS += mainwindow.h DEPENDPATH += /home/amruz/worksharedlib INCLUDEPATH += /home/amruz/worksharedlib LIBS += -L/home/amruz/build-worksharedlib-Desktop_Qt_5_7_0_GCC_64bit-Debug -lworksharedlib
-
@amruz Yes. You're using widgets - so it must be a gui application with widgets, right?
QT += core gui widgets