(epics)QT compilation error: "undefined reference to" - qt

I am brand new to programming with Qt. I'm trying to do a simple subtraction of some values fed from an epicsQt widget called QELabel, which simply reads the value of an EPICS channel. I want to subtract values from two QELabels and print it to another QELabel. But, I'm getting 'undefined reference to' errors for these ->
MainWindow::on_qeLabel_dbValueChanged(QString const&) MainWindow::on_ShutterOpen_dbValueChanged(QString const&)
Here is the bit of mainwindow.cpp (I followed the example from this youtube video, especially after about the 15 minute mark)
void MainWindow::on_TopShutter_dbValueChanged(const QString &out)
{
double top,bottom,open;
top=ui->TopShutter->text().toDouble();
bottom=ui->BottomShutter->text().toDouble();
open=top-bottom
ui->ShutterOpen->setText(Qstring::number(open));
}
I'm using QTCreator, so I don't have the usual errors that I've been seeing in other forums. I have the slot declared in the header file, and MainWindow set as a Q_Object (this is the whole mainwindow.h file):
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void on_qelabel_dbValueChanged(const QString &out);
void on_ShutterOpen_dbValueChanged(const QString &out);
void on_TopShutter_dbValueChanged(const QString &out);
private:
Ui::MainWindow *ui;
};
#endif //MAINWINDOW_H
Because they are short, and for completeness, here is the main.cpp, and then the .pro
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
And the FirstWeatherAlarm.pro:
#-------------------------------------------------
QT += core gui xml
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = FirstWeatherAlarm
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
LIBS += -L/usr/lib64/qt5/plugins/designer -lQEPlugin
INCLUDEPATH += /home/jchavez/epicsqt/3.1.0/framework/include
HEADERS += mainwindow.h
FORMS += mainwindow.ui
Have I got everything declared right at the start of all the files? What is missing so that my slots are not right? I created the slot in the gui, using the "right-click" on my QELabel, and selecting "Go to Slot", so I should think all the formatting would be correct. As I've been editing, I've also run qmake and make clean which are other answers I've seen on forums. But nothing is working.

The problem is with two slots:
MainWindow::on_qeLabel_dbValueChanged(QString const&)
MainWindow::on_ShutterOpen_dbValueChanged(QString const&)
They are declared in MainWindow.h file and used somewhere in your project (otherwise you won't get an error).
But they are not implemented in mainwindow.cpp. You should add implementation to this file and the error will go away.
You have implementation for
void MainWindow::on_TopShutter_dbValueChanged(const QString &out)
in mainwindow.cpp, you can add implementation for two more slots. Think about slot as a function. And read more about signals/slots.

Related

QML start external program: use QProcess fail build [duplicate]

I wrote a little program with a my own class within the main.cpp. Here the code:
#include <QApplication>
#include <QPushButton>
#include <QLabel>
class MyWidget : public QWidget {
//Q_OBJECT
public:
MyWidget(QWidget* parent = 0);
QLabel* label;
QString string;
signals:
public slots:
void setTextLabel();
};
void MyWidget::setTextLabel() {
label->setText("Test");
}
MyWidget::MyWidget(QWidget* parent)
: QWidget(parent) {
}
int main(int argc, char** argv) {
QApplication app(argc, argv);
MyWidget widget;
widget.show();
return app.exec();
}
it seems work but not "completely". My slot doens't work. I suppose i have to put Q_OBJECT. BUT, doing so, I got a list of errors, like this:
undefined reference to `vtable for MyWidget'
........................................
collect2: error: ld returned 1 exit status
make: *** [mywidget] Error 1
I can I manage that? Where the problem?
Signals and slots in Qt are managed through the moc: meta object compiler. Basically, the moc generates additional C++ code for each class containing the Q_OBJECT macro in order to implement effectively the signals and slots mechanisms. The additional code is then linked to the original class declaration.
The problem here is that your class is declared in main.cpp: this conflicts with how the moc is working with your code. You should declare your class in a separate header.
More about the moc
Edit: as hyde pointed, an alternative is to include in your cpp the file generated by the moc: Why is important to include “.moc” file at end of a Qt Source code file?
just append the line #include"main.moc" to your cpp source file should be enough.
More information:
Why is important to include ".moc" file at end of a Qt Source code file?

QT 5.6 with OPenCV Run time 0xc0000139

Anyone got QT 5.6 working with OpenCV ?
Tried OpenCV latest 2.4.13 (at time of writing) and went back to OpenCV 2.4.9.
None worked - program will compile, link but crash on "During Startup program exited with code 0xc0000139". I never had any problems with QT 5.5.1 and OpenCV.
Here is stripped down code:
**mainwindow.cpp:**
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <opencv/cv.h>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
cv::Mat image = cv::imread("C:/Users/foo/pics/cheetah.jpg");
cv::namedWindow("My Image");
cv::imshow("My Image", image);
cvWaitKey(0);
}
MainWindow::~MainWindow()
{
delete ui;
}
**main.cpp (used default):**
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
**mainwindow.h: (used default)**
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
**test_opencv.pro:**
INCLUDEPATH += "C:\Users\foo\Downloads\opencv\build\include"
LIBS += -LC:\Users\foo\Downloads\opencv\build\lib \
-lopencv_core249.dll \
-lopencv_highgui249.dll \
-lopencv_imgproc249.dll \
-lopencv_features2d249.dll \
-lopencv_video249.dll \
-lopencv_calib3d249.dll
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = test_opencv
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
Path set:
C:\Qt\Tools\mingw492_32\bin
C:\Qt\5.6\mingw49_32\bin
C:\Users\foo\Downloads\opencv\build\bin
QT works fine with no OpenCV calls. With above code, running with QT Debug will see this:
"During Startup program exited with code 0xc0000139".
QT Error message
I have double checked my path. The OpenCV DLLs are defined in the Path. problem is not about not finding the runtime dynamically link dlls. I also checked my System32 and other directories for any old OpenCV dlls that might interfere as the path is traversed. No issues.
OpenCV was built with CMake and successfully build and installed. No issues there.
Thanks
Sean

QT the glBegin not declared?

i'm following a tutorial to write a small piece of code of opengl in qt.here's the link
http://www.youtube.com/watch?v=1nzHSkY4K18
but in the 6:13 when I bluid the code it show a couple of error that
..\testopgl\glwidget.cpp: In member function 'virtual void GLWidget::paintGL()':
..\testopgl\glwidget.cpp:17:20: error: 'glColor3f' was not declared in this scope
..\testopgl\glwidget.cpp:19:25: error: 'glBegin' was not declared in this scope
..\testopgl\glwidget.cpp:20:31: error: 'glVertex3f' was not declared in this scope
..\testopgl\glwidget.cpp:23:11: error: 'glEnd' was not declared in this scope
..\testopgl\glwidget.cpp: At global scope:
what I really don't understand is when I only put the glClear(GL_COLOR_BUFFER_BIT) it builds alright,but occurs error even i just put the glColor3f().Does the GLWidget not support the glColor*() or glBegin() command?
here's my code.
testopgl.pro
#-------------------------------------------------
#
# Project created by QtCreator 2013-03-28T09:48:44
#
#-------------------------------------------------
QT += core gui opengl
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = testopgl
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
glwidget.cpp
HEADERS += mainwindow.h \
glwidget.h
FORMS += mainwindow.ui
glwidget.h
#ifndef GLWIDGET_H
#define GLWIDGET_H
#include <QGLWidget>
class GLWidget : public QGLWidget
{
Q_OBJECT
public:
explicit GLWidget(QWidget *parent = 0);
void initializeGL();
void paintGL();
void resizeGL(int w,int h);
};
#endif // GLWIDGET_H
glwidget.cpp
#include "glwidget.h"
GLWidget::GLWidget(QWidget *parent) :
QGLWidget(parent)
{
}
void GLWidget::initializeGL(){
glClearColor(1,1,0,1);
}
void GLWidget::paintGL(){
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1,0,0);
glBegin(GL_TRIANGLES);
glVertex3f(-0.5,-0.5,0);
glVertex3f(0.5,-0.5,0);
glVertex3f(0.0,0.5,0);
glEnd();
}
void GLWidget::resizeGL(int w,int h){
}
The functions you mention are simply not present in any modern version of GL, so the tutorial you are following sounds like it is quite out of date.
So probably the version of GL exposed through your build of QT does not have these functions. It may be possible to reconfigure/rebuild QT to use an older version of GL, but I would instead recommend getting to know and use the modern programmable interface.

Why is my mainwindow closing automatically when called from a differnet class?

I can't seem to figure out what went wrong so I'm here to ask you. I have made a simple class called BOBSNetworkSessionManager defined below. It is a simple class that inherits the QOBject so that I can use signals and slots but it does not have a dialog or any kind of window associated with it. It will eventually call a log in dialog and use the credentials to connect to a tcp server that I have created. This class serves as a layer to manage the connection state of the program because it will only run properly when connected to the server and when being used within 15 minutes without break due to p.c.i. compliance. If these conditions are not true this class will lock the window and force a new login. As of right now I just try to arbitrarily open the main window as though credentials had passed and i wasbconnected to the server. The problem is when I open the mainwindow it disapears right away. I cannot seem to figure out why it is diappearing. I have included all of my files.
BOBSDCNetworkSessionManager .h header file
#ifndef BOBSDCNETWORKSESSIONMANAGER_H
#define BOBSDCNETWORKSESSIONMANAGER_H
#include <QObject>
#include <QSettings>
class BOBSDCNetworkSessionManager : public QObject
{
Q_OBJECT
public:
explicit BOBSDCNetworkSessionManager(QObject *parent = 0);
protected:
void destroyed(QObject *);
signals:
public slots:
private:
void readSettings();
void writeSettings();
QSettings networkSettings;
};
#endif // BOBSDCNETWORKSESSIONMANAGER_H
BOBSDCNetworkSessionManager Implementation .cpp file
#include "bobsdcnetworksessionmanager.h"
#include "bobsmainwindow.h"
BOBSDCNetworkSessionManager::BOBSDCNetworkSessionManager(QObject *parent) :
QObject(parent)
{
BOBSMainWindow w;
w.show();
}
Main.cpp file
#include "bobsdcnetworksessionmanager.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
a.setApplicationName("Enterprise Management Suite");
a.setApplicationVersion("Beta Version: 0.0.0.01");
a.setOrganizationName("Enigma Web Consulting");
a.setOrganizationDomain("http://www.EnigmaWebCo.com");
BOBSDCNetworkSessionManager netMgr;
return a.exec();
}
The problem is here:
{
BOBSMainWindow w;
w.show();
}
w.show() is not a blocking call. So you're creating a window, showing it, and then it immediately is destructed when it goes out of scope. You should either declare w as a member variable or construct it on the heap:
BOBSMainWindow *w = new BOBSMainWindow(this);

Cannot read output using readyReadStandardOutput in Qt

I am using Qt and I am unable to get output of a exe file using readyReadStandardOutput.
Here is my code.
mainwindow.cpp
void MainWindow::on_pushButton_24_clicked()
{
myprocess = new QProcess(this);
myprocess->start("files\\helloworld.exe");
connect(myprocess, SIGNAL(readyReadStandardOutput ()), this, SLOT(outlog()));
}
void MainWindow::outlog()
{
QString abc;
abc = myprocess->readAllStandardOutput();
emit outlogtext(abc);
ui->lineEdit_4->setText(abc);
}
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QtGui>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
QProcess *myprocess;
signals:
void outlogtext(QString ver);
private slots:
void outlog();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
The helloworld.exe will just give a output "Hello world" but I cannot see it in the textEdit, whats wrong with my code? I am very new to Qt. Thank you
I got the program working. Below is the code.
mainwindow.hpp
#ifndef MAINWINDOW_HPP
#define MAINWINDOW_HPP
#include <QtGui>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
signals:
void outlogtext(QString ver);
private slots:
void outlog();
void on_pushButton_24_clicked();
private:
QPushButton* pushButton_24;
QLineEdit* lineEdit_4;
QProcess *myprocess;
};
#endif // MAINWINDOW_HPP
main.cpp
#include <QtCore>
#include <QtGui>
#include <QDebug>
#include "mainwindow.hpp"
MainWindow::MainWindow(QWidget* parent)
: QMainWindow(parent)
{
pushButton_24 = new QPushButton;
connect(pushButton_24, SIGNAL(clicked()),
this, SLOT(on_pushButton_24_clicked()));
lineEdit_4 = new QLineEdit;
QWidget* central = new QWidget;
QLayout* layout = new QVBoxLayout();
layout->addWidget(pushButton_24);
layout->addWidget(lineEdit_4);
central->setLayout(layout);
setCentralWidget(central);
}
MainWindow::~MainWindow()
{
}
void MainWindow::on_pushButton_24_clicked()
{
myprocess = new QProcess(this);
connect(myprocess, SIGNAL(readyReadStandardOutput()),
this, SLOT(outlog()));
myprocess->start("./helloworld.exe");
// For debugging: Wait until the process has finished.
myprocess->waitForFinished();
qDebug() << "myprocess error code:" << myprocess->error();
}
void MainWindow::outlog()
{
QString abc = myprocess->readAllStandardOutput();
emit outlogtext(abc);
lineEdit_4->setText(abc);
}
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
MainWindow win;
win.show();
return app.exec();
}
helloworld.cpp
#include <iostream>
int main()
{
std::cout << "Hello World!" << std::endl;
}
Some things I changed:
After constructing an object, I always connect signals and slots before performing the
actual operation on the object, which might be calling show() for widgets or calling
start() for threads. So I can be sure that I do not miss a signal like started(),
for example.
I ran the program on Linux. There I had to make sure that helloworld.exe was on my
path and I changed the command to ./helloworld.exe. I didn't create the sub-directory
called files as in your example.
The character to separate directories in Qt is the slash /. There are special functions to convert between the Qt-style and the native-style, when you want to display something to the user. Internally always make use of slashes. This even works for Windows programs (many console commands can cope with a slash instead of a backslash, too).
Adding debug output is really, really valuable during development. If the Makefile is
not set up correctly or something breaks, the helloworld.exe might end up in a directory, where it is not expected. Thus, I added code to wait for some time until the process has finished. This does not hurt because helloworld.exe needs just some milliseconds to run. Afterwards, I print the error code of QProcess just to be sure that the program has been found and could be executed. So I can be sure that the executable is on my path, that the executable flag is set, that I have permissions for executing the file etc.
I don't know exactly what causes the problem on your machine. However, comparing your solution to mine, having a look at the error code of QProcess and setting break points inside the slots should help you finding the error.

Resources