I have an error when i tried to connect the tcp server and mainwindow and the themewidget
-
Hi guys im trying to connect the tcp server to the theme widget so that the theme widget.cpp can get the data and i followed the steps like how the tcp server is connected to the tcp console however i have an error stating that there is a undefined referance to theme widget....below is my code
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "console.h"
#include "tcpconsole.h"
#include "settingsdialog.h"
#include "tcpsettingdialog.h"
#include "tcpserver.h"
#include "themewidget.h"#include <QLabel>
#include <QMessageBox>
#include <QTabWidget>//tcpserver TCPServer;
//! [0]
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
m_ui(new Ui::MainWindow),
m_status(new QLabel),
m_console(new Console),
m_tcpconsole(new TCPConsole),
m_settings(new SettingsDialog),
m_tcpsettingdialog(new tcpsettingdialog),
m_themewidget(new ThemeWidget),m_TCPServer(new tcpserver),
\
//! [1]
m_serial(new QSerialPort(this))
//! [1]
{
//! [0]
m_ui->setupUi(this);
m_console->setEnabled(false);
m_tcpconsole->setEnabled(false);ThemeWidget *m_hschart = new ThemeWidget(); QTabWidget *tabs = new QTabWidget();
// tabs->addTab(m_console,"Serial Console");
tabs->addTab(m_tcpconsole,"TCP/IP Console");
//tabs->addTab(new QWidget(),"High Speed ADC");
tabs->addTab(m_hschart,"High Speed Chart");//THIHA //setCentralWidget(m_console); setCentralWidget(tabs); m_ui->actionConnect->setEnabled(true); m_ui->actionDisconnect->setEnabled(false); m_ui->actionQuit->setEnabled(true); m_ui->actionConfigure->setEnabled(true); m_ui->actionTCP_Settings->setEnabled(true); m_ui->actionStart_TCP_Server->setEnabled(true); m_ui->actionStop_TCP_Server->setEnabled(false); m_ui->statusBar->addWidget(m_status); initActionsConnections(); connect(m_serial, &QSerialPort::errorOccurred, this, &MainWindow::handleError);
//! [2]
connect(m_serial, &QSerialPort::readyRead, this, &MainWindow::readData);
//! [2]
connect(m_console, &Console::getData, this, &MainWindow::writeData);
// update the status
connect(m_tcpsettingdialog, &tcpsettingdialog::finished, this, &MainWindow::updatestatus);
connect(m_TCPServer, &tcpserver::tcpDataGUI, this, &MainWindow::tcpreadData);
// connect(m_tcpconsole, &TCPConsole::getData, this, &MainWindow::writeData);connect(m_TCPServer, &tcpserver::themewidgetdata, this, &MainWindow::tcpreadData);
//! [3]
}
//! [3]MainWindow::~MainWindow()
{
delete m_settings;
delete m_ui;
}//! [4]
void MainWindow::openSerialPort()
{
const SettingsDialog::Settings p = m_settings->settings();
m_serial->setPortName(p.name);
m_serial->setBaudRate(p.baudRate);
m_serial->setDataBits(p.dataBits);
m_serial->setParity(p.parity);
m_serial->setStopBits(p.stopBits);
m_serial->setFlowControl(p.flowControl);
if (m_serial->open(QIODevice::ReadWrite)) {
m_console->setEnabled(true);
m_console->setLocalEchoEnabled(p.localEchoEnabled);
m_ui->actionConnect->setEnabled(false);
m_ui->actionDisconnect->setEnabled(true);
m_ui->actionConfigure->setEnabled(false);
showStatusMessage(tr("Connected to %1 : %2, %3, %4, %5, %6")
.arg(p.name).arg(p.stringBaudRate).arg(p.stringDataBits)
.arg(p.stringParity).arg(p.stringStopBits).arg(p.stringFlowControl));
} else {
QMessageBox::critical(this, tr("Error"), m_serial->errorString());showStatusMessage(tr("Open error")); }
}
//! [4]//! [5]
void MainWindow::closeSerialPort()
{
if (m_serial->isOpen())
m_serial->close();
m_console->setEnabled(false);
m_ui->actionConnect->setEnabled(true);
m_ui->actionDisconnect->setEnabled(false);
m_ui->actionConfigure->setEnabled(true);
showStatusMessage(tr("Disconnected"));
}
//! [5]void MainWindow::about()
{
QMessageBox::about(this, tr("The HPDAQ GUI Application"),
tr("The <b>HPDAQ GUI</b> appllication is to"
"communication with HPDAQ hardware through TCP IP Communication."
));
}//! [6]
void MainWindow::writeData(const QByteArray &data)
{
m_serial->write(data);
}
//! [6]//! [7]
void MainWindow::readData()
{
const QByteArray data = m_serial->readAll();
m_console->putData(data);
m_themewidget->putData(data);
}void MainWindow::tcpreadData(const QByteArray &data)
{
const tcpsettingdialog::TcpSettings tcp = m_tcpsettingdialog->tcpSettings();m_tcpconsole->putData(data); m_themewidget->putData(data); // Put data into m_themewidget if(tcp.dataLoggerEnabled) { QString dataString = QString::fromStdString(data.toStdString()); datalogger(dataString); }
}
//! [7]//! [8]
void MainWindow::handleError(QSerialPort::SerialPortError error)
{
if (error == QSerialPort::ResourceError) {
QMessageBox::critical(this, tr("Critical Error"), m_serial->errorString());
closeSerialPort();
}
}
//! [8]void MainWindow::initActionsConnections()
{
connect(m_ui->actionConnect, &QAction::triggered, this, &MainWindow::openSerialPort);
connect(m_ui->actionDisconnect, &QAction::triggered, this, &MainWindow::closeSerialPort);
connect(m_ui->actionQuit, &QAction::triggered, this, &MainWindow::close);
connect(m_ui->actionConfigure, &QAction::triggered, m_settings, &SettingsDialog::show);
connect(m_ui->actionClear, &QAction::triggered, m_tcpconsole, &TCPConsole::clear);
connect(m_ui->actionAbout, &QAction::triggered, this, &MainWindow::about);
connect(m_ui->actionTCP_Settings, &QAction::triggered, m_tcpsettingdialog, &tcpsettingdialog::show);connect(m_ui->actionStart_TCP_Server, &QAction::triggered, this, &MainWindow::startTCPServer); connect(m_ui->actionStop_TCP_Server, &QAction::triggered, this, &MainWindow::stopTCPServer);
}
void MainWindow::showStatusMessage(const QString &message)
{
m_status->setText(message);
}void MainWindow::updatestatus()
{
const tcpsettingdialog::TcpSettings tcp = m_tcpsettingdialog->tcpSettings();
//update to status
m_status->setText(tr("Set to Port: %1") .arg(tcp.portno));
}void MainWindow::startTCPServer()
{
const tcpsettingdialog::TcpSettings tcp = m_tcpsettingdialog->tcpSettings();
int portNum = 3000;
if(tcp.portno != 0)
{
portNum = tcp.portno;
}m_TCPServer->startServer(portNum); m_ui->actionStart_TCP_Server->setEnabled(false); m_ui->actionStop_TCP_Server->setEnabled(true);
}
void MainWindow::stopTCPServer()
{
m_TCPServer->stopServer();
m_ui->actionStart_TCP_Server->setEnabled(true);
m_ui->actionStop_TCP_Server->setEnabled(false);
}void MainWindow::datalogger(QString &value)
{
QString text = value;
QString filename = "hpdaqlog.txt";
QFile file(filename);if(file.open(QIODevice::Append | QIODevice::Text)) { QTextStream out(&file); out.setEncoding(QStringConverter::Utf8); out << text; file.close(); } //QTextStream out()
}
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H#include <QMainWindow>
#include <QSerialPort>
#include <QFile>
#include <QTextStream>QT_BEGIN_NAMESPACE
class QLabel;
namespace Ui {
class MainWindow;
}QT_END_NAMESPACE
class Console;
class SettingsDialog;
class TCPConsole;
class tcpsettingdialog;
class tcpserver;
class ThemeWidget;class MainWindow : public QMainWindow
{
Q_OBJECTpublic:
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow();private slots:
void openSerialPort();
void closeSerialPort();
void about();
void writeData(const QByteArray &data);
void readData();
void updatestatus();
void startTCPServer();
void stopTCPServer();
void tcpreadData(const QByteArray &data);void handleError(QSerialPort::SerialPortError error);
private:
void initActionsConnections(); void datalogger(QString &value);
private:
void showStatusMessage(const QString &message);Ui::MainWindow *m_ui = nullptr; QLabel *m_status = nullptr; Console *m_console = nullptr; TCPConsole *m_tcpconsole = nullptr; SettingsDialog *m_settings = nullptr; tcpsettingdialog *m_tcpsettingdialog = nullptr; tcpserver *m_TCPServer=nullptr; QSerialPort *m_serial = nullptr; QFile *file;
ThemeWidget *m_themewidget = nullptr;
};
#endif // MAINWINDOW_H
tcpconsole.cpp
#include "tcpconsole.h"#include <QScrollBar>
TCPConsole::TCPConsole(QWidget *parent) :
QPlainTextEdit(parent)
{
document()->setMaximumBlockCount(100);
QPalette p = palette();
p.setColor(QPalette::Base, Qt::black);
p.setColor(QPalette::Text, Qt::green);
setPalette(p);
}void TCPConsole::putData(const QByteArray &data)
{
insertPlainText(data);QScrollBar *bar = verticalScrollBar(); bar->setValue(bar->maximum());
}
void TCPConsole::setLocalEchoEnabled(bool set)
{
m_localEchoEnabled = set;
}void TCPConsole::keyPressEvent(QKeyEvent *e)
{
switch (e->key()) {
case Qt::Key_Backspace:
case Qt::Key_Left:
case Qt::Key_Right:
case Qt::Key_Up:
case Qt::Key_Down:
break;
default:
if (m_localEchoEnabled)
QPlainTextEdit::keyPressEvent(e);
emit getData(e->text().toLocal8Bit());
}
}void TCPConsole::mousePressEvent(QMouseEvent *e)
{
Q_UNUSED(e)
setFocus();
}void TCPConsole::mouseDoubleClickEvent(QMouseEvent *e)
{
Q_UNUSED(e)
}void TCPConsole::contextMenuEvent(QContextMenuEvent *e)
{
Q_UNUSED(e)
}tcpconsole.h
#ifndef TCPCONSOLE_H
#define TCPCONSOLE_H#include <QPlainTextEdit>
class TCPConsole : public QPlainTextEdit
{
Q_OBJECTsignals:
void getData(const QByteArray &data);public:
explicit TCPConsole(QWidget *parent = nullptr);void putData(const QByteArray &data); void setLocalEchoEnabled(bool set);
protected:
void keyPressEvent(QKeyEvent *e) override;
void mousePressEvent(QMouseEvent *e) override;
void mouseDoubleClickEvent(QMouseEvent *e) override;
void contextMenuEvent(QContextMenuEvent *e) override;private:
bool m_localEchoEnabled = false;
};#endif // TCPCONSOLE_H
Tcp server.cpp
#include "tcpserver.h"
#include "tcpthread.h"tcpserver::tcpserver(QObject *parent) : QTcpServer(parent)
{}
void tcpserver::startServer(int portno)
{
//int port = 1234;if(!this->listen(QHostAddress::Any, portno)) { qDebug() << "Could not start server"; } else { qDebug() << "Listening to port " << portno << "..."; }
}
void tcpserver::stopServer()
{
this->close();
}// This function is called by QTcpServer when a new connection is available.
void tcpserver::incomingConnection(qintptr socketDescriptor)
{
// We have a new connection
qDebug() << socketDescriptor << " Connecting...";// Every new connection will be run in a newly created thread Tcpthread *thread = new Tcpthread(socketDescriptor, this); connect(thread, SIGNAL(tcpIncomingdata(QString)), this, SLOT(getdata(QString))); // connect signal/slot // once a thread is not needed, it will be deleted later connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); thread->start();
}
void tcpserver::getdata(QString data)
{
QByteArray rx_data= data.toUtf8();
emit tcpDataGUI(rx_data);
emit themewidgetdata(rx_data);
}
tcpserver.h
#ifndef TCPSERVER_H
#define TCPSERVER_H#include <QTcpServer>
class tcpserver : public QTcpServer
{
Q_OBJECT
public:
explicit tcpserver(QObject *parent = nullptr);void startServer(int portno); void stopServer();
private slots:
void getdata(QString data);signals:
void tcpDataGUI(const QByteArray &data);
void themewidgetdata(const QByteArray &data);protected:
void incomingConnection(qintptr socketDescriptor);};
#endif // TCPSERVER_H
-
Hi guys im trying to connect the tcp server to the theme widget so that the theme widget.cpp can get the data and i followed the steps like how the tcp server is connected to the tcp console however i have an error stating that there is a undefined referance to theme widget....below is my code
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "console.h"
#include "tcpconsole.h"
#include "settingsdialog.h"
#include "tcpsettingdialog.h"
#include "tcpserver.h"
#include "themewidget.h"#include <QLabel>
#include <QMessageBox>
#include <QTabWidget>//tcpserver TCPServer;
//! [0]
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
m_ui(new Ui::MainWindow),
m_status(new QLabel),
m_console(new Console),
m_tcpconsole(new TCPConsole),
m_settings(new SettingsDialog),
m_tcpsettingdialog(new tcpsettingdialog),
m_themewidget(new ThemeWidget),m_TCPServer(new tcpserver),
\
//! [1]
m_serial(new QSerialPort(this))
//! [1]
{
//! [0]
m_ui->setupUi(this);
m_console->setEnabled(false);
m_tcpconsole->setEnabled(false);ThemeWidget *m_hschart = new ThemeWidget(); QTabWidget *tabs = new QTabWidget();
// tabs->addTab(m_console,"Serial Console");
tabs->addTab(m_tcpconsole,"TCP/IP Console");
//tabs->addTab(new QWidget(),"High Speed ADC");
tabs->addTab(m_hschart,"High Speed Chart");//THIHA //setCentralWidget(m_console); setCentralWidget(tabs); m_ui->actionConnect->setEnabled(true); m_ui->actionDisconnect->setEnabled(false); m_ui->actionQuit->setEnabled(true); m_ui->actionConfigure->setEnabled(true); m_ui->actionTCP_Settings->setEnabled(true); m_ui->actionStart_TCP_Server->setEnabled(true); m_ui->actionStop_TCP_Server->setEnabled(false); m_ui->statusBar->addWidget(m_status); initActionsConnections(); connect(m_serial, &QSerialPort::errorOccurred, this, &MainWindow::handleError);
//! [2]
connect(m_serial, &QSerialPort::readyRead, this, &MainWindow::readData);
//! [2]
connect(m_console, &Console::getData, this, &MainWindow::writeData);
// update the status
connect(m_tcpsettingdialog, &tcpsettingdialog::finished, this, &MainWindow::updatestatus);
connect(m_TCPServer, &tcpserver::tcpDataGUI, this, &MainWindow::tcpreadData);
// connect(m_tcpconsole, &TCPConsole::getData, this, &MainWindow::writeData);connect(m_TCPServer, &tcpserver::themewidgetdata, this, &MainWindow::tcpreadData);
//! [3]
}
//! [3]MainWindow::~MainWindow()
{
delete m_settings;
delete m_ui;
}//! [4]
void MainWindow::openSerialPort()
{
const SettingsDialog::Settings p = m_settings->settings();
m_serial->setPortName(p.name);
m_serial->setBaudRate(p.baudRate);
m_serial->setDataBits(p.dataBits);
m_serial->setParity(p.parity);
m_serial->setStopBits(p.stopBits);
m_serial->setFlowControl(p.flowControl);
if (m_serial->open(QIODevice::ReadWrite)) {
m_console->setEnabled(true);
m_console->setLocalEchoEnabled(p.localEchoEnabled);
m_ui->actionConnect->setEnabled(false);
m_ui->actionDisconnect->setEnabled(true);
m_ui->actionConfigure->setEnabled(false);
showStatusMessage(tr("Connected to %1 : %2, %3, %4, %5, %6")
.arg(p.name).arg(p.stringBaudRate).arg(p.stringDataBits)
.arg(p.stringParity).arg(p.stringStopBits).arg(p.stringFlowControl));
} else {
QMessageBox::critical(this, tr("Error"), m_serial->errorString());showStatusMessage(tr("Open error")); }
}
//! [4]//! [5]
void MainWindow::closeSerialPort()
{
if (m_serial->isOpen())
m_serial->close();
m_console->setEnabled(false);
m_ui->actionConnect->setEnabled(true);
m_ui->actionDisconnect->setEnabled(false);
m_ui->actionConfigure->setEnabled(true);
showStatusMessage(tr("Disconnected"));
}
//! [5]void MainWindow::about()
{
QMessageBox::about(this, tr("The HPDAQ GUI Application"),
tr("The <b>HPDAQ GUI</b> appllication is to"
"communication with HPDAQ hardware through TCP IP Communication."
));
}//! [6]
void MainWindow::writeData(const QByteArray &data)
{
m_serial->write(data);
}
//! [6]//! [7]
void MainWindow::readData()
{
const QByteArray data = m_serial->readAll();
m_console->putData(data);
m_themewidget->putData(data);
}void MainWindow::tcpreadData(const QByteArray &data)
{
const tcpsettingdialog::TcpSettings tcp = m_tcpsettingdialog->tcpSettings();m_tcpconsole->putData(data); m_themewidget->putData(data); // Put data into m_themewidget if(tcp.dataLoggerEnabled) { QString dataString = QString::fromStdString(data.toStdString()); datalogger(dataString); }
}
//! [7]//! [8]
void MainWindow::handleError(QSerialPort::SerialPortError error)
{
if (error == QSerialPort::ResourceError) {
QMessageBox::critical(this, tr("Critical Error"), m_serial->errorString());
closeSerialPort();
}
}
//! [8]void MainWindow::initActionsConnections()
{
connect(m_ui->actionConnect, &QAction::triggered, this, &MainWindow::openSerialPort);
connect(m_ui->actionDisconnect, &QAction::triggered, this, &MainWindow::closeSerialPort);
connect(m_ui->actionQuit, &QAction::triggered, this, &MainWindow::close);
connect(m_ui->actionConfigure, &QAction::triggered, m_settings, &SettingsDialog::show);
connect(m_ui->actionClear, &QAction::triggered, m_tcpconsole, &TCPConsole::clear);
connect(m_ui->actionAbout, &QAction::triggered, this, &MainWindow::about);
connect(m_ui->actionTCP_Settings, &QAction::triggered, m_tcpsettingdialog, &tcpsettingdialog::show);connect(m_ui->actionStart_TCP_Server, &QAction::triggered, this, &MainWindow::startTCPServer); connect(m_ui->actionStop_TCP_Server, &QAction::triggered, this, &MainWindow::stopTCPServer);
}
void MainWindow::showStatusMessage(const QString &message)
{
m_status->setText(message);
}void MainWindow::updatestatus()
{
const tcpsettingdialog::TcpSettings tcp = m_tcpsettingdialog->tcpSettings();
//update to status
m_status->setText(tr("Set to Port: %1") .arg(tcp.portno));
}void MainWindow::startTCPServer()
{
const tcpsettingdialog::TcpSettings tcp = m_tcpsettingdialog->tcpSettings();
int portNum = 3000;
if(tcp.portno != 0)
{
portNum = tcp.portno;
}m_TCPServer->startServer(portNum); m_ui->actionStart_TCP_Server->setEnabled(false); m_ui->actionStop_TCP_Server->setEnabled(true);
}
void MainWindow::stopTCPServer()
{
m_TCPServer->stopServer();
m_ui->actionStart_TCP_Server->setEnabled(true);
m_ui->actionStop_TCP_Server->setEnabled(false);
}void MainWindow::datalogger(QString &value)
{
QString text = value;
QString filename = "hpdaqlog.txt";
QFile file(filename);if(file.open(QIODevice::Append | QIODevice::Text)) { QTextStream out(&file); out.setEncoding(QStringConverter::Utf8); out << text; file.close(); } //QTextStream out()
}
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H#include <QMainWindow>
#include <QSerialPort>
#include <QFile>
#include <QTextStream>QT_BEGIN_NAMESPACE
class QLabel;
namespace Ui {
class MainWindow;
}QT_END_NAMESPACE
class Console;
class SettingsDialog;
class TCPConsole;
class tcpsettingdialog;
class tcpserver;
class ThemeWidget;class MainWindow : public QMainWindow
{
Q_OBJECTpublic:
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow();private slots:
void openSerialPort();
void closeSerialPort();
void about();
void writeData(const QByteArray &data);
void readData();
void updatestatus();
void startTCPServer();
void stopTCPServer();
void tcpreadData(const QByteArray &data);void handleError(QSerialPort::SerialPortError error);
private:
void initActionsConnections(); void datalogger(QString &value);
private:
void showStatusMessage(const QString &message);Ui::MainWindow *m_ui = nullptr; QLabel *m_status = nullptr; Console *m_console = nullptr; TCPConsole *m_tcpconsole = nullptr; SettingsDialog *m_settings = nullptr; tcpsettingdialog *m_tcpsettingdialog = nullptr; tcpserver *m_TCPServer=nullptr; QSerialPort *m_serial = nullptr; QFile *file;
ThemeWidget *m_themewidget = nullptr;
};
#endif // MAINWINDOW_H
tcpconsole.cpp
#include "tcpconsole.h"#include <QScrollBar>
TCPConsole::TCPConsole(QWidget *parent) :
QPlainTextEdit(parent)
{
document()->setMaximumBlockCount(100);
QPalette p = palette();
p.setColor(QPalette::Base, Qt::black);
p.setColor(QPalette::Text, Qt::green);
setPalette(p);
}void TCPConsole::putData(const QByteArray &data)
{
insertPlainText(data);QScrollBar *bar = verticalScrollBar(); bar->setValue(bar->maximum());
}
void TCPConsole::setLocalEchoEnabled(bool set)
{
m_localEchoEnabled = set;
}void TCPConsole::keyPressEvent(QKeyEvent *e)
{
switch (e->key()) {
case Qt::Key_Backspace:
case Qt::Key_Left:
case Qt::Key_Right:
case Qt::Key_Up:
case Qt::Key_Down:
break;
default:
if (m_localEchoEnabled)
QPlainTextEdit::keyPressEvent(e);
emit getData(e->text().toLocal8Bit());
}
}void TCPConsole::mousePressEvent(QMouseEvent *e)
{
Q_UNUSED(e)
setFocus();
}void TCPConsole::mouseDoubleClickEvent(QMouseEvent *e)
{
Q_UNUSED(e)
}void TCPConsole::contextMenuEvent(QContextMenuEvent *e)
{
Q_UNUSED(e)
}tcpconsole.h
#ifndef TCPCONSOLE_H
#define TCPCONSOLE_H#include <QPlainTextEdit>
class TCPConsole : public QPlainTextEdit
{
Q_OBJECTsignals:
void getData(const QByteArray &data);public:
explicit TCPConsole(QWidget *parent = nullptr);void putData(const QByteArray &data); void setLocalEchoEnabled(bool set);
protected:
void keyPressEvent(QKeyEvent *e) override;
void mousePressEvent(QMouseEvent *e) override;
void mouseDoubleClickEvent(QMouseEvent *e) override;
void contextMenuEvent(QContextMenuEvent *e) override;private:
bool m_localEchoEnabled = false;
};#endif // TCPCONSOLE_H
Tcp server.cpp
#include "tcpserver.h"
#include "tcpthread.h"tcpserver::tcpserver(QObject *parent) : QTcpServer(parent)
{}
void tcpserver::startServer(int portno)
{
//int port = 1234;if(!this->listen(QHostAddress::Any, portno)) { qDebug() << "Could not start server"; } else { qDebug() << "Listening to port " << portno << "..."; }
}
void tcpserver::stopServer()
{
this->close();
}// This function is called by QTcpServer when a new connection is available.
void tcpserver::incomingConnection(qintptr socketDescriptor)
{
// We have a new connection
qDebug() << socketDescriptor << " Connecting...";// Every new connection will be run in a newly created thread Tcpthread *thread = new Tcpthread(socketDescriptor, this); connect(thread, SIGNAL(tcpIncomingdata(QString)), this, SLOT(getdata(QString))); // connect signal/slot // once a thread is not needed, it will be deleted later connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater())); thread->start();
}
void tcpserver::getdata(QString data)
{
QByteArray rx_data= data.toUtf8();
emit tcpDataGUI(rx_data);
emit themewidgetdata(rx_data);
}
tcpserver.h
#ifndef TCPSERVER_H
#define TCPSERVER_H#include <QTcpServer>
class tcpserver : public QTcpServer
{
Q_OBJECT
public:
explicit tcpserver(QObject *parent = nullptr);void startServer(int portno); void stopServer();
private slots:
void getdata(QString data);signals:
void tcpDataGUI(const QByteArray &data);
void themewidgetdata(const QByteArray &data);protected:
void incomingConnection(qintptr socketDescriptor);};
#endif // TCPSERVER_H
@DemonLord
Please learn to use forum Code tags when pasting code.
Do you think you should produce a minimal example to illustrate your issue rather than just pasting hundreds of lines?i have an error stating that there is a undefined referance to theme widget
Does it mention a line number or say nothing about the location? Do you want to paste the error message?
-
sorry i dont understand what you mean im very very new to qt and yeah if you can tell me whats wrong with my code cause i dont understand the error thanks
@DemonLord said in I have an error when i tried to connect the tcp server and mainwindow and the themewidget:
i dont understand the error
Then please post the whole error and tell us in which line it occurs! Many readers (me including) will not spend their time reading such amount of code and trying to guess where the error actually occurs.
And you should also think about how you are asking: you post a big amount of code and expect others to find out what is wrong with it? You should do what @JonB suggested: create a MINIMAL application which shows that problem and post its the code here (instead of posting a big amount of code where most of it is not relevant for the issue). -
@DemonLord
Please learn to use forum Code tags when pasting code.
Do you think you should produce a minimal example to illustrate your issue rather than just pasting hundreds of lines?i have an error stating that there is a undefined referance to theme widget
Does it mention a line number or say nothing about the location? Do you want to paste the error message?
@JonB yes this the error
void MainWindow::tcpreadData(const QByteArray &data)
{
const tcpsettingdialog::TcpSettings tcp = m_tcpsettingdialog->tcpSettings();m_tcpconsole->putData(data);
m_themewidget->putData(data); // Put data into m_themewidget//error says undefined reference to themewidget -
@JonB yes this the error
void MainWindow::tcpreadData(const QByteArray &data)
{
const tcpsettingdialog::TcpSettings tcp = m_tcpsettingdialog->tcpSettings();m_tcpconsole->putData(data);
m_themewidget->putData(data); // Put data into m_themewidget//error says undefined reference to themewidget@DemonLord said in I have an error when i tried to connect the tcp server and mainwindow and the themewidget:
undefined reference to themewidget
Does it? Not
m_themewidget
? Since this is "surprising", any reason you still do not paste the error message? -
@DemonLord said in I have an error when i tried to connect the tcp server and mainwindow and the themewidget:
undefined reference to themewidget
Does it? Not
m_themewidget
? Since this is "surprising", any reason you still do not paste the error message?@JonB sorry for the delay I placed the error below
error: undefined reference to
ThemeWidget::putData(QByteArray const&)' debug/mainwindow.o: In function
MainWindow::tcpreadData(QByteArray const&)':undefined reference to `ThemeWidget::putData(QByteArray const&)'
-
@JonB sorry for the delay I placed the error below
error: undefined reference to
ThemeWidget::putData(QByteArray const&)' debug/mainwindow.o: In function
MainWindow::tcpreadData(QByteArray const&)':undefined reference to `ThemeWidget::putData(QByteArray const&)'
@DemonLord said in I have an error when i tried to connect the tcp server and mainwindow and the themewidget:
ThemeWidget::putData(QByteArray const&)
So, did you define this method?
Do you also compile/link the cpp file where it is defined? -
@DemonLord said in I have an error when i tried to connect the tcp server and mainwindow and the themewidget:
ThemeWidget::putData(QByteArray const&)
So, did you define this method?
Do you also compile/link the cpp file where it is defined?@jsulm no it shows that this line has the error
m_themewidget->putData(data); // error
error: undefined reference to ThemeWidget::putData(QByteArray const&)' debug/mainwindow.o: In functionMainWindow::tcpreadData(QByteArray const&)':
undefined reference to `ThemeWidget::putData(QByteArray const&)'
What does that mean?
-
@jsulm no it shows that this line has the error
m_themewidget->putData(data); // error
error: undefined reference to ThemeWidget::putData(QByteArray const&)' debug/mainwindow.o: In functionMainWindow::tcpreadData(QByteArray const&)':
undefined reference to `ThemeWidget::putData(QByteArray const&)'
What does that mean?
@DemonLord said in I have an error when i tried to connect the tcp server and mainwindow and the themewidget:
What does that mean?
It means that this method (ThemeWidget::putData(QByteArray const&)) was declared in the class but not defined (implemented).
Do you have this in your ThemeWidget cpp file:void ThemeWidget::putData(QByteArray const&) { ... }
?
If you have - did you add it to your pro file?