I'm trying to build a really simple Qt program using FFMpeg library.
Currently I just want to open and close a video file.
Here is my project file:
QT += core gui
TARGET = avtest01
TEMPLATE = app
INCLUDEPATH += /usr/local/include
LIBS += -L/usr/local/lib -lavformat
SOURCES += main.cpp
And my code:
#include <QDebug>
extern "C" {
#include <libavformat/avformat.h>
}
int main(int argc, char *argv[])
{
if(argc > 1)
{
AVFormatContext *format_context;
qDebug() << argv[1];
if(avformat_open_input(&format_context, argv[1], NULL, NULL) == 0)
{
qDebug() << "open";
avformat_close_input(&format_context);
}
else
qDebug() << "error opening " << argv[1];
}
return 0;
}
Unfortunately, the linker fails:
Undefined symbols for architecture x86_64:
"avformat_open_input(AVFormatContext**, char const*, AVInputFormat*, AVDictionary**)", referenced from:
_main in main.o
"avformat_close_input(AVFormatContext**)", referenced from:
_main in main.o
I'm using Qt 5.1.0 on MacOS.
Your code worked for me after I added av_register_all(); to main.
My guess is that you have avformat compiled for 32 bit. You can confirm by running file /usr/local/lib/libavformat.dylib in terminal.
The output should look like:
/usr/local/lib/libavformat.dylib: Mach-O 64-bit dynamically linked shared library x86_64
Related
So I've created a qrc file and have a file at /stylesheets/main.qss.
I have stylesheet information in this main.qss file. My goal here is to have a qss file I can work out of and potentially hot reload over time. My issue is that when I debug there is no /stylesheets/main.qss in the debug build location. So it loads the file as an empty string, don't even get an exception. What am I missing?
main.qss
/*#MainBackgroundColor = rgb(40,40,40)*/
/*#MainBorderColor = rgb(0,102,255)*/
/*#MainTextColor = rgb(255,255,255)*/
*
{
color: rgb(255,255,255);
background-color: rgb(40,40,40);
}
QStatusBar
{
border-top: 3px solid rgb(0,102,255);
}
Loading the stylesheet
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
//We want a frameless window.
setWindowFlags(Qt::FramelessWindowHint);
//Load the style sheet into the window
QFile File(":/stylesheets/main.qss");
File.open(QFile::ReadOnly);
QString stylesheet = QLatin1String(File.readAll());
//Setup the UI
ui->setupUi(this);
this->setStyleSheet(stylesheet);
}
MainWindow::~MainWindow()
{
delete ui;
}
resources.qrc
<RCC>
<qresource prefix="/">
<file>stylesheets/main.qss</file>
</qresource>
</RCC>
.pro file
#-------------------------------------------------
#
# Project created by QtCreator 2019-02-20T18:02:31
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = SmartDraw
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
CONFIG += c++11
SOURCES += \
main.cpp \
mainwindow.cpp \
stylesheetloader.cpp
HEADERS += \
mainwindow.h \
stylesheetloader.h
FORMS += \
mainwindow.ui
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
RESOURCES += \
resources.qrc
DISTFILES += \
stylesheets/main.qss
EDIT: Found the solution. Apparently Qt isn't very good about updating everything if you happen to have the pro file open. If something super obviously wrong happens like this you need to run Build->Clean All then Build->Run QMake to get everything stituated again.
What I do is keep the stylesheet file (*.qss) next to the app while debugging. Then load it in main.cpp and subscribe for changes using QFileSystemWatcher.
This way I can edit the *.qss file with a nice editor, like SublimeText, and every time I save it, I can see the changes inmediatly:
#include "mydialog.h"
#include <QApplication>
#include <QDebug>
#include <QFile>
#include <QTextStream>
#include <QSharedPointer>
#include <QFileSystemWatcher>
typedef QSharedPointer<QFileSystemWatcher> QWatcherPtr;
void setStyleSheet(QApplication &a, const QString &strPath, const bool &subscribe = false)
{
// set stylesheet
QFile f(strPath);
if (!f.exists())
{
qDebug() << "[ERROR] Unable to set stylesheet," << strPath << "file not found.";
}
else
{
// set stylesheet
f.open(QFile::ReadOnly | QFile::Text);
QTextStream ts(&f);
a.setStyleSheet(ts.readAll());
f.close();
// subscribe to changes (only once)
if (!subscribe)
{
return;
}
QWatcherPtr watcher = QWatcherPtr(new QFileSystemWatcher);
watcher->addPath(strPath);
QObject::connect(watcher.data(), &QFileSystemWatcher::fileChanged, &a,
[&a, watcher, strPath]()
{
setStyleSheet(a, strPath, false);
});
}
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
// set stylesheet and subscribe to changes
setStyleSheet(a, "./style.qss", true);
MyDialog w;
w.show();
return a.exec();
}
Iam using Ubuntu 16.04 in which i have installed Qtcreator. I would like to work on SNMP. for this i have already installed net-snmp as well as mibs downloader.
I have taken example code from net-snmp (snmpdemoapp.c) and tried implementing same in qt.
#include "mainwindow.h"
#include <QApplication>
#include <string.h>
#include <cstring>
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
//using namespace std;
#define DEMO_USE_SNMP_VERSION_3
#ifdef DEMO_USE_SNMP_VERSION_3
const char *our_v3_passphase="The Net SNMP Pass Phrase";
#endif
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
//*******************SNMP Code starts from here
netsnmp_session session,*ss;
netsnmp_pdu *pdu;
netsnmp_pdu *response;
oid anOID[MAX_OID_LEN];
size_t anOID_len;
netsnmp_variable_list *vars;
int status;
int count=1;
//initialize the snmp library
init_snmp("snmpdemoapp");
//SnmpGet
//initialize the session that defines who we are going to talk to
snmp_sess_init(&session);
session.peername="test.net-snmp.org";
//set up the authentication parameters for talking to server
#ifdef DEMO_USE_SNMP_VERSION_3
//if snmp version3
session.version=SNMP_VERSION_3;
//set the SNMP v3 user name
session.securityName=strdup("MD5User");
session.securityNameLen=strlen(session.securityName);
//snmp security
session.securityLevel=SNMP_SEC_LEVEL_AUTHNOPRIV;
session.securityAuthProto=usmHMACMD5AuthProtocol;
session.securityAuthProtoLen=sizeof(usmHMACMD5AuthProtocol)/sizeof(oid);
session.securityAuthKeyLen=USM_AUTH_KU_LEN;
/* set the authentication key to a MD5 hashed version of our
passphrase "The UCD Demo Password" (which must be at least 8
characters long) */
if(generate_Ku(session.securityAuthProto,session.securityAuthProtoLen,(uchar *)our_v3_passphase,
strlen(our_v3_passphase),session.securityAuthKey,&session.securityAuthKeyLen)!=SNMPERR_SUCCESS)
{
snmp_perror(argv[0]);
snmp_log(LOG_ERR,"Error generating Ku from authentication pass phrase. \n");
exit(1);
}
#else
//if snmp version is snmp v1
session.version=SNMP_VERSION_1;
/* set the SNMPv1 community name used for authentication */
session.community="demopublic";
session.community_len=strlen(session.community);
#endif
SOCK_STARTUP;
ss = snmp_open(&session); /* establish the session */
if (!ss) {
snmp_sess_perror("ack", &session);
SOCK_CLEANUP;
exit(1);
}
/*
* Create the PDU for the data for our request.
* 1) We're going to GET the system.sysDescr.0 node.
*/
pdu = snmp_pdu_create(SNMP_MSG_GET);
anOID_len = MAX_OID_LEN;
if (!snmp_parse_oid(".1.3.6.1.2.1.1.1.0", anOID, &anOID_len)) {
snmp_perror(".1.3.6.1.2.1.1.1.0");
SOCK_CLEANUP;
exit(1);
}
#if OTHER_METHODS
/*
* These are alternatives to the 'snmp_parse_oid' call above,
* e.g. specifying the OID by name rather than numerically.
*/
read_objid(".1.3.6.1.2.1.1.1.0", anOID, &anOID_len);
get_node("sysDescr.0", anOID, &anOID_len);
read_objid("system.sysDescr.0", anOID, &anOID_len);
#endif
snmp_add_null_var(pdu, anOID, anOID_len);
/*
* Send the Request out.
*/
status = snmp_synch_response(ss, pdu, &response);
/*
* Process the response.
*/
if (status == STAT_SUCCESS && response->errstat == SNMP_ERR_NOERROR) {
/*
* SUCCESS: Print the result variables
*/
for(vars = response->variables; vars; vars = vars->next_variable)
print_variable(vars->name, vars->name_length, vars);
/* manipuate the information ourselves */
for(vars = response->variables; vars; vars = vars->next_variable) {
if (vars->type == ASN_OCTET_STR) {
char *sp = (char *)malloc(1 + vars->val_len);
memcpy(sp, vars->val.string, vars->val_len);
sp[vars->val_len] = '\0';
printf("value #%d is a string: %s\n", count++, sp);
free(sp);
}
else
printf("value #%d is NOT a string! Ack!\n", count++);
}
} else {
/*
* FAILURE: print what went wrong!
*/
if (status == STAT_SUCCESS)
fprintf(stderr, "Error in packet\nReason: %s\n",
snmp_errstring(response->errstat));
else if (status == STAT_TIMEOUT)
fprintf(stderr, "Timeout: No response from %s.\n",
session.peername);
else
snmp_sess_perror("snmpdemoapp", ss);
}
/*
* Clean up:
* 1) free the response.
* 2) close the session.
*/
if (response)
snmp_free_pdu(response);
snmp_close(ss);
SOCK_CLEANUP;
//*************************SNMP code ends here
w.show();
return a.exec();
}
when iam building the program, iam getting errors s below:
main.o: In function `main':
/home/srinivas/QT_Projects/build-SNMP_Demo_Example-Desktop_Qt_5_7_0_GCC_64bit-Debug/../SNMP_Demo_Example/main.cpp:42: undefined reference to `init_snmp'
/home/srinivas/QT_Projects/build-SNMP_Demo_Example-Desktop_Qt_5_7_0_GCC_64bit-Debug/../SNMP_Demo_Example/main.cpp:48: undefined reference to `snmp_sess_init'
Makefile:216: recipe for target 'SNMP_Demo_Example' failed
/home/srinivas/QT_Projects/build-SNMP_Demo_Example-Desktop_Qt_5_7_0_GCC_64bit-Debug/../SNMP_Demo_Example/main.cpp:66: undefined reference to `usmHMACMD5AuthProtocol'
/home/srinivas/QT_Projects/build-SNMP_Demo_Example-Desktop_Qt_5_7_0_GCC_64bit-Debug/../SNMP_Demo_Example/main.cpp:74: undefined reference to `generate_Ku'
/home/srinivas/QT_Projects/build-SNMP_Demo_Example-Desktop_Qt_5_7_0_GCC_64bit-Debug/../SNMP_Demo_Example/main.cpp:77: undefined reference to `snmp_perror'
/home/srinivas/QT_Projects/build-SNMP_Demo_Example-Desktop_Qt_5_7_0_GCC_64bit-Debug/../SNMP_Demo_Example/main.cpp:78: undefined reference to `snmp_log'
/home/srinivas/QT_Projects/build-SNMP_Demo_Example-Desktop_Qt_5_7_0_GCC_64bit-Debug/../SNMP_Demo_Example/main.cpp:97: undefined reference to `snmp_open'
/home/srinivas/QT_Projects/build-SNMP_Demo_Example-Desktop_Qt_5_7_0_GCC_64bit-Debug/../SNMP_Demo_Example/main.cpp:100: undefined reference to `snmp_sess_perror'
/home/srinivas/QT_Projects/build-SNMP_Demo_Example-Desktop_Qt_5_7_0_GCC_64bit-Debug/../SNMP_Demo_Example/main.cpp:109: undefined reference to `snmp_pdu_create'
/home/srinivas/QT_Projects/build-SNMP_Demo_Example-Desktop_Qt_5_7_0_GCC_64bit-Debug/../SNMP_Demo_Example/main.cpp:111: undefined reference to `snmp_parse_oid'
/home/srinivas/QT_Projects/build-SNMP_Demo_Example-Desktop_Qt_5_7_0_GCC_64bit-Debug/../SNMP_Demo_Example/main.cpp:112: undefined reference to `snmp_perror'
/home/srinivas/QT_Projects/build-SNMP_Demo_Example-Desktop_Qt_5_7_0_GCC_64bit-Debug/../SNMP_Demo_Example/main.cpp:127: undefined reference to `snmp_add_null_var'
/home/srinivas/QT_Projects/build-SNMP_Demo_Example-Desktop_Qt_5_7_0_GCC_64bit-Debug/../SNMP_Demo_Example/main.cpp:132: undefined reference to `snmp_synch_response'
/home/srinivas/QT_Projects/build-SNMP_Demo_Example-Desktop_Qt_5_7_0_GCC_64bit-Debug/../SNMP_Demo_Example/main.cpp:143: undefined reference to `print_variable'
/home/srinivas/QT_Projects/build-SNMP_Demo_Example-Desktop_Qt_5_7_0_GCC_64bit-Debug/../SNMP_Demo_Example/main.cpp:163: undefined reference to `snmp_errstring'
/home/srinivas/QT_Projects/build-SNMP_Demo_Example-Desktop_Qt_5_7_0_GCC_64bit-Debug/../SNMP_Demo_Example/main.cpp:169: undefined reference to `snmp_sess_perror'
/home/srinivas/QT_Projects/build-SNMP_Demo_Example-Desktop_Qt_5_7_0_GCC_64bit-Debug/../SNMP_Demo_Example/main.cpp:179: undefined reference to `snmp_free_pdu'
/home/srinivas/QT_Projects/build-SNMP_Demo_Example-Desktop_Qt_5_7_0_GCC_64bit-Debug/../SNMP_Demo_Example/main.cpp:180: undefined reference to `snmp_close'
collect2: error: ld returned 1 exit status
make: *** [SNMP_Demo_Example] Error 1
13:04:19: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project SNMP_Demo_Example (kit: Desktop Qt 5.7.0 GCC 64bit)
When executing step "Make"
what could be the error????
this is my .pro file
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = SNMP_Demo_Example
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
INCLUDEPATH += /usr/local/include/net-snmp
INCLUDEPATH += /usr/local/include/net-snmp/agent
INCLUDEPATH += /usr/local/include/net-snmp/library
INCLUDEPATH += /usr/local/include/net-snmp/machine
INCLUDEPATH += /usr/local/include/net-snmp/system
unix:!macx: LIBS += -L$$PWD/../../../../usr/local/lib/ -lnetsnmp
INCLUDEPATH += $$PWD/../../../../usr/local/include
DEPENDPATH += $$PWD/../../../../usr/local/include
unix:!macx: LIBS += -L$$PWD/../../../../usr/local/lib/ -lnetsnmpagent
INCLUDEPATH += $$PWD/../../../../usr/local/include
DEPENDPATH += $$PWD/../../../../usr/local/include
unix:!macx: LIBS += -L$$PWD/../../../../usr/local/lib/ -lnetsnmphelpers
INCLUDEPATH += $$PWD/../../../../usr/local/include
DEPENDPATH += $$PWD/../../../../usr/local/include
unix:!macx: LIBS += -L$$PWD/../../../../usr/local/lib/ -lnetsnmpmibs
INCLUDEPATH += $$PWD/../../../../usr/local/include
DEPENDPATH += $$PWD/../../../../usr/local/include
unix:!macx: LIBS += -L$$PWD/../../../../usr/local/lib/ -lnetsnmptrapd
INCLUDEPATH += $$PWD/../../../../usr/local/include
DEPENDPATH += $$PWD/../../../../usr/local/include
Until now I was working with OpenCV in VS 2012. Everything worked. Now I'm trying to work in QtCreator but I have a problem. When I run the project in debug I get the error:
"C:\Qt\Qt5.0.2\Tools\QtCreator\bin\DetectorPietoni\mainwindow.cpp:4: error: C1083: Cannot open include file: 'opencv2/core/core.hpp': No such file or directory"
In release mode I get the error:
"mainwindow.obj:-1: error: LNK2019: unresolved external symbol "class cv::Mat __cdecl cv::imread(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,int)" (?imread#cv##YA?AVMat#1#AEBV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##H#Z) referenced in function "private: void __cdecl MainWindow::on_pushButton_clicked(void)" (?on_pushButton_clicked#MainWindow##AEAAXXZ)".
The code I am running is the next:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
cv::Mat img = cv::imread("C:\\PedestrianDetectionDataset\\test\\pos\\1.png");
}
And my setting are:
TARGET = DetectorPietoni
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
INCLUDEPATH += C:\OpenCV-2.4.5\\opencv\build\include
CONFIG(release,debug|release)
{
LIBS += C:\\OpenCV-2.4.5\\opencv\\build\\x64\\vc11\\lib\\opencv_core245.lib \
C:\\OpenCV-2.4.5\\opencv\\build\\x64\\vc11\\lib\\opencv_features2d245.lib \
C:\\OpenCV-2.4.5\\opencv\\build\\x64\\vc11\\lib\\opencv_highgui245.lib \
C:\\OpenCV-2.4.5\\opencv\\build\\x64\\vc11\\lib\\opencv_imgproc245.lib \
C:\\OpenCV-2.4.5\\opencv\\build\\x64\\vc11\\lib\\opencv_ml245.lib
}
CONFIG(debug,debug|release)
{
LIBS += C:\\OpenCV-2.4.5\\opencv\\build\\x64\\vc11\\lib\\opencv_core245d.lib \
C:\\OpenCV-2.4.5\\opencv\\build\\x64\\vc11\\lib\\opencv_features2d245d.lib \
C:\\OpenCV-2.4.5\\opencv\\build\\x64\\vc11\\lib\\opencv_highgui245d.lib \
C:\\OpenCV-2.4.5\\opencv\\build\\x64\\vc11\\lib\\opencv_imgproc245d.lib \
C:\\OpenCV-2.4.5\\opencv\\build\\x64\\vc11\\lib\\opencv_ml245d.lib
}
Any ideeas?
Try coping opencv.hpp from C:\OpenCV-2.4.5\opencv\build\include\opencv2 to C:\OpenCV-2.4.5\opencv\build\include
Then it might be able to locate the include.
I'm trying to create a boost::thread application in Qt.
Here is my code:
#include <iostream>
#include "boost/thread.hpp"
#include "boost/bind.hpp"
using namespace std;
class A {
public:
void tf() {
for (int i = 0; i < 100; ++i) {
cout << i << endl;
}
}
};
int main()
{
boost::shared_ptr<A> aPtr;
cout << "Hello World!" << endl;
boost::thread t = boost::thread(boost::bind(&A::tf, aPtr.get()));
cout << "Thread started" << endl;
return 0;
}
And the corresponding .pro file:
TEMPLATE = app
CONFIG += console
CONFIG -= qt
LIBS += -L"C:/Program Files (x86)/boost/boost_1_49/lib"
DEPENDPATH += "C:/Program Files (x86)/boost/boost_1_49"
INCLUDEPATH += "C:/Program Files (x86)/boost/boost_1_49"
SOURCES += main.cpp
When i try to compile it i get:
{{path}}\main.cpp:21: error: undefined reference to `_imp___ZN5boost6threadD1Ev'
{{path}}\main.o:-1: In function `ZN5boost6threadC1INS_3_bi6bind_tIvNS_4_mfi3mf0Iv1AEENS2_5list1INS2_5valueIPS6_EEEEEEEET_NS_10disable_ifINS_14is_convertibleIRSE_NS_6detail13thread_move_tISE_EEEEPNS0_5dummyEE4typeE':
c:\Program Files (x86)\boost\boost_1_49\boost\thread\detail\thread.hpp:205: error: undefined reference to `_imp___ZN5boost6thread12start_threadEv'
collect2.exe:-1: error: error: ld returned 1 exit status
Whats the problem?
What am i missing?
M.
You aren't linking to the Boost Thread library, you are just telling Qt where it is.
LIBS += -L"C:/Program Files (x86)/boost/boost_1_49/lib" -lboost_thread
#include <QtCore/QCoreApplication>
#include <QTCore>
#include <QtNetwork>
#include <QDebug>
#define CONNECT(sndr, sig, rcvr, slt) connect(sndr, SIGNAL(sig), rcvr, SLOT(slt))
class mynet : QObject
{
Q_OBJECT
public:
mynet()
{}
void start()
{
CONNECT(tcpServer, newConnection(), this, acceptConnection());
CONNECT(tcpClient, connected(), this, startTransfer());
CONNECT(tcpClient, bytesWritten(qint64), this, updateClientProgress(qint64));
CONNECT(tcpClient, error(QAbstractSocket::SocketError), this, displayError(QAbstractSocket::SocketError));
// start server listening
tcpServer->listen();
while(!tcpServer->isListening());
// make client connection
tcpClient->connectToHost(QHostAddress::LocalHost, tcpServer->serverPort());
}
public slots:
void acceptConnection()
{
tcpServerConnection = tcpServer->nextPendingConnection();
CONNECT(tcpServerConnection, readyRead(), this, updateServerProgress());
CONNECT(tcpServerConnection, error(QAbstractSocket::SocketError), this, displayError(QAbstractSocket));
tcpServer->close();
}
void startTransfer()
{
bytesToWrite = TotalBytes - (int)tcpClient->write(QByteArray(PayloadSize, '#'));
}
void updateServerProgress()
{
bytesReceived += (int)tcpServerConnection->bytesAvailable();
tcpServerConnection->readAll();
if (bytesReceived == TotalBytes)
{
qDebug() << "done";
tcpServerConnection->close();
}
}
void updateClientProgress(qint64 numBytes)
{
// callen when the TCP client has written some bytes
bytesWritten += (int)numBytes;
// only write more if not finished and when the Qt write buffer is below a certain size.
if (bytesToWrite > 0 && tcpClient->bytesToWrite() <= 4*PayloadSize)
bytesToWrite -= (int)tcpClient->write(QByteArray(qMin(bytesToWrite, PayloadSize), '#'));
}
void displayError(QAbstractSocket::SocketError socketError)
{
if (socketError == QTcpSocket::RemoteHostClosedError)
return;
qDebug() << tcpClient->errorString();
tcpClient->close();
tcpServer->close();
}
private:
QTcpServer* tcpServer;
QTcpSocket* tcpClient;
QTcpSocket* tcpServerConnection;
int bytesToWrite;
int bytesWritten;
int bytesReceived;
int TotalBytes;
int PayloadSize;
};
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
mynet m1;
m1.start();
return a.exec();
}
I get an
Undefined symbols for architecture x86_64:
"vtable for mynet", referenced from:
mynet::mynet() in main.o
mynet::~mynet()in main.o.
Please advise what I am doing wrong. Can I not inline the method definitions in the class for some reason in Qt?
You need to add your class to the .pro file
HEADERS += mynet.h
SOURCES += mynet.cpp
so the meta-object compiler can scan them and work out they need moc'ing and generate the relevant stubs.
Assuming that your source file is named foo.cpp, you have to put the following line at the very end:
#include "foo.moc"
This line tells qmake and the VS Qt add-in that the file should be run via moc, and that the generated moc file should be named foo.moc.
You also have problems in the #include lines for Qt headers. I've found that the following work:
#include <QtCore/QCoreApplication>
#include <QtNetwork/QTcpServer>
#include <QtNetwork/QTcpSocket>
Make sure to add network to your .pro file. This will create the correct linking to the network library functions.
QT += core network
Two things:
1) You should publicly derive from QObject.
2) Are you moc'ing this file and then compiling and linking the output? If you include the Q_OBJECT macro and don't moc, you will get an error like that.