QT undefined reference error (Qextserialport) - c++

i found this code for QT Creator and am brand new to the IDE, but have been trying to get this code to run. The main error I am seeing is about 12 instances of similar errors related to Qextserialport.
C:\Users\Hassman\Downloads\aQtLow\aQtLow\dtransferusb.cpp:
34: error: undefined reference to `QextSerialPort::QextSerialPort(QextSerialPort::QueryMode, QObject*)'
I'm not quite sure what to do about it, and am kind of lost. I am running QTCreator 5.1.1 and I imagine there may be a compatibility issue, but please someone give me a hand. Maybe I haven't linked the header to my file correctly? Any suggestions would be appreciated!
#include "dtransferusb.h"
#include <QDebug>
#include <QByteArray>
#include "C:/Users/Hassman/Downloads/aQtLow/aQtLow/qextserialport/src/qextserialport.h"
#include "C:/Users/Hassman/Downloads/aQtLow/aQtLow/qextserialport/src/qextserialport_p.h"
#include "globals.h"
dtransferusb::dtransferusb(QObject *parent) :
QThread(parent)
{
}
void dtransferusb::run()
{
SerPort= new QextSerialPort();
int ExpectedLength = NUMBER_OF_REGISTERS * 2 + NUMBER_OF_COILS / 8 + 1;
QTime Startup, Sleeper;
Startup.start();
while(!Shutdown)
{
if(SerPort->isOpen())
{//the port is open so check for data
Sleeper.start();
while((ExpectingResponse > 0) && (SerPort->bytesAvailable() < ExpectedLength))
{
msleep(25);
if(Sleeper.elapsed() > 5000) break;
}
if(SerPort->bytesAvailable() >= ExpectedLength)
{//data found
Receive(ExpectedLength);
}
else
{
if((ExpectingResponse > 2) && (Startup.elapsed() > 15000))
{
qDebug() << "DTxfrUsb " << QString::number(Cfg.DTxfrUsb) << " finds the lack of expected response utterly demoralizing " << SerPort->portName() << " " << QDateTime::currentDateTime().toString(TIMESTAMP_FORMAT);
P[Cfg.Prc].CommFailure();
ExpectingResponse = 0;
SerPort->close();
Sleeper.start();
while(Sleeper.elapsed() < 1000) msleep(100);
}
else
{
if(!WriteRequest())
{
Send(1,0,0); //Function 1 siginfies "gimme data"
}
}
}
}
else
{//need to open the port
SerPort->reset();
SerPort->setPortName(Cfg.Port);
SerPort->setBaudRate(BAUD9600);
SerPort->setDataBits(DATA_8);
SerPort->setStopBits(STOP_1);
SerPort->setFlowControl(FLOW_OFF);
SerPort->setParity(PAR_NONE);
SerPort->setTimeout(1000);

QextSerialPort is a 3rd-party library that is not affiliated with the official Qt Project. You can find it at https://code.google.com/p/qextserialport/ -- You will need to install QextSerialPort separately.
Some extra notes:
Since you are new, I recommend using Qt 5.2.1 instead. It has many new features and bug fixes over Qt 5.1.1.
"Qt Creator" is the name of the IDE, "Qt" is the name of the libraries. The current version of the IDE is Qt Creator 3.1, the current version of the libraries is Qt 5.2.1.
Qt has its own built-in QSerialPort class, which I recommend if you want to write your own code.

(1) To use these classes in your application, use the following include statement:
#include <QtSerialPort/QtSerialPort>
(2) To link against the module, add this line to your qmake .pro file:
QT += serialport
Qt Serial Port Documentation

Related

Connect To Matlab 2017b from c++ vs2013

I would like to read some variable's value in Matlab from c++. I searched in Internet and found out below example in Matlab Documentation Page.
for using this example I Did below steps:
I add this include path to project :
c:\program files\Matlab\r2017b\extern\include
then I Add this path Library Directory :
c:\program Files\Matlab\r2017b\extern\lib\win64\microsoft
then I Add this library to project :
"libMatlabEngine.lib"
"libMatlabDataArray.lib"
then I placed needed DLLs beside application EXE file.
then I ran the application after that application faced with access violataion error when startMATLAB() Method has been ran.
Note: I had other problem that I resolved it. but I think that problem was very strange and may be knowing that problem help you to find main reason of my problems.
problem was : when I set dll's files path in environment variables my app didn't find dlls and get "no entry point to *.dll" run time error. but when I copy dlls beside of exe, my app saw them.(I restarted VS2013 after change environment variables.)
#include "MatlabDataArray.hpp"
#include "MatlabEngine.hpp"
#include <iostream>
void callgetVars() {
using namespace matlab::engine;
// Start MATLAB engine synchronously
std::unique_ptr<MATLABEngine> matlabPtr = startMATLAB();
// Evaluate MATLAB statement
matlabPtr->eval(convertUTF8StringToUTF16String("[az,el,r] = cart2sph(5,7,3);"));
// Get the result from MATLAB
matlab::data::TypedArray<double> result1 = matlabPtr->
getVariable(convertUTF8StringToUTF16String("az"));
matlab::data::TypedArray<double> result2 = matlabPtr->
getVariable(convertUTF8StringToUTF16String("el"));
matlab::data::TypedArray<double> result3 = matlabPtr->
getVariable(convertUTF8StringToUTF16String("r"));
// Display results
std::cout << "az: " << result1[0] << std::endl;
std::cout << "el: " << result2[0] << std::endl;
std::cout << "r: " << result3[0] << std::endl;
}
I use vs2013 and Matlab 2017b in windows 7.
Thanks for your help.

Issue updating curves in QwtPlot 6.1.3

I am currently working on Ubuntu 14.04, using gcc 4.9.2 and Qwt 6.1.3; I have installed both Qt 4.8.6 and Qt 5.2.1 (and I wonder whether this could be connected to the issues I am experiencing).
I have a simple GUI with a QwtPlot and a QwtPlotCurve attached, which I am trying to update and redraw. In the setupUi() function, I create a few random data points and then plot them:
void ExampleMainWindow::setupUi(QMainWindow* mainWindow)
{
// run the inherited setupUi
Ui_MainWindow::setupUi(mainWindow);
// associate internal pointer to main window
this->mainWindow = mainWindow;
// create some data points
for(unsigned int i = 0; i < 10; i++)
{
this->createDataPoint();
}
for(unsigned int i = 0; i < this->xPlot.size(); i++)
{
cout << "Point #" << i << ": x=" << xPlot[i] << "; y=" << yPlot[i] << endl;
}
this->updateGraph();
// also, connect stuff
connect( this->pushButton, SIGNAL(clicked()), this, SLOT(synchronous()) );
return;
}
Now, this part works as it should. The result is something like this:
Later, I connected the pushButton to a method that should add 10 points to the curve and replot it. The relevant methods are:
void ExampleMainWindow::synchronous()
{
cout << "Creating 10 new data points..." << endl;
for(unsigned int i = 0; i < 10; i++) this->createDataPoint();
cout << "xPlot.size() = " << xPlot.size() << " ; yPlot.size() = " << yPlot.size() << endl;
this->updateGraph();
return;
}
void ExampleMainWindow::updateGraph()
{
// detach everything?
this->qwtPlot->detachItems();
// create a new curve
QwtPlotCurve* curve = new QwtPlotCurve("curve 1");
curve->setSamples( QVector<double>::fromStdVector( xPlot ), QVector<double>::fromStdVector( yPlot ) );
curve->attach( this->qwtPlot );
this->qwtPlot->replot();
//this->qwtPlot->show();
return;
}
Now, the issue is that pressing the pushButton on the GUI does not visually change anything in the QwtPlot. I am sure the program enters synchronous when the pushButton is clicked. So, there is probably something wrong with the function updateGraph, but I am missing something, as I cannot find the issue.
When I compile the project, I use Qt 4.8.6, with
qmake-qt4
make
and I get no compiling errors. My Qt project file is:
TEMPLATE = app
TARGET = example
QT += widgets
CONFIG += qwt
QMAKE_CXXFLAGS += -std=c++11
DEPENDPATH += ../. \
# for Qwt
/usr/local/qwt-6.1.3-svn/lib \
/usr/local/qwt-6.1.3-svn/include
# end for Qwt
INCLUDEPATH += ../. \
# for Qwt
/usr/local/qwt-6.1.3-svn/include
# end for Qwt
LIBS += -lqwt \
-L/usr/local/qwt-6.1.3-svn/lib
# Input
FORMS += example.ui
HEADERS = ExampleMainWindow.h
SOURCES = ExampleMainWindow.cpp \
main.cpp
Even looking at the examples I found online, I am unable to find the problem. Can you help me?
Thanks in advance for your support :-)
EDIT: The phrase pointing out the issue was cut out by mistake.
Ok, after several trials and errors, I found a solution: I installed Qwt (I guess 6.0) through Ubuntu's Software Center, and removed all the other Qwt versions (6.1.2 and 6.1.3) that I had manually installed. Now, the small GUI is working properly.
I guess the error was due to some issue in the paths I provided in the .pro file, but I could not pinpoint the exact mistake. Not really a satisfying answer, but at least it works.

how to compile blacklib (c++)

I am running a beaglebone and want to write a program to sample the ADC. I am trying to use the blacklib (http://blacklib.yigityuce.com/index.html) from here. I cloned the git:
https://github.com/yigityuce/BlackLib
and tried to compile the example with
g++ exampleAndTiming.cpp -std=c++11
This however gives me a ton of errors like these:
In file included from exampleAndTiming.cpp:33:0:
exampleAndTiming/exampleAndTiming_GPIO.h: In function 'void exampleAndTiming_GPIO()':
exampleAndTiming/exampleAndTiming_GPIO.h:97:12: error: 'sleep' was not declared in this scope
sleep(1);
^
In file included from exampleAndTiming.cpp:34:0:
exampleAndTiming/exampleAndTiming_ADC.h: In function 'void exampleAndTiming_ADC()':
exampleAndTiming/exampleAndTiming_ADC.h:67:16: error: 'usleep' was not declared in this scope
usleep(1000);
^
so I include unistd.h (in exampleAndTiming.cpp), but then I get errors like these:
/tmp/ccbgiXE9.o: In function `exampleAndTiming_GPIO()':
exampleAndTiming.cpp:(.text+0x50): undefined reference to `Timing::startMeasure(std::string)'
exampleAndTiming.cpp:(.text+0x80): undefined reference to `BlackLib::BlackGPIO::BlackGPIO(BlackLib::gpioName, BlackLib::direction, BlackLib::workingMode)'
exampleAndTiming.cpp:(.text+0xbc): undefined reference to `Timing::endMeasure(std::string)'
exampleAndTiming.cpp:(.text+0xec): undefined reference to `BlackLib::BlackGPIO::BlackGPIO(BlackLib::gpioName, BlackLib::direction, BlackLib::workingMode)'
exampleAndTiming.cpp:(.text+0x104): undefined reference to `BlackLib::BlackGPIO::BlackGPIO(BlackLib::gpioName, BlackLib::direction, BlackLib::workingMode)'
exampleAndTiming.cpp:(.text+0x11c): undefined reference to `BlackLib::BlackGPIO::BlackGPIO(BlackLib::gpioName, BlackLib::direction, BlackLib::workingMode)'
exampleAndTiming.cpp:(.text+0x158): undefined reference to `Timing::startMeasure(std::string)'
I've been looking at some library examples and compiling it, but I cannot make sense of it all. I've compiled plenty of c++ and c programs before, but I can't get this one to work. So any help will be appreciated.
COMPLETE GUIDE how to compile BLACKLIB directly on BEAGLEBONE BLACK (rev C) running ANGSTROM:
Programs:
Putty - to communicate with BBB from Windows (using SSH with USB cable)
WinSCP - to manage (upload, create, delete) files directly on BBB
Code::Blocks - to write C++ programs
optionally
Termite 2.9 - to send and receive UART transmission from UART<->USB converter (actually Putty could be used to do that as well)
1) get the BlackLib from official site
2) unzip the library and copy following files into separate folder :
BlackADC.cpp, BlackADC.h, BlackCore.cpp, BlackCore.h, BlackDef.h, BlackErr.h, BlackGPIO.cpp, BlackGPIO.h, BlackI2C.cpp, BlackI2C.h, BlackLib.h, BlackPWM.cpp, BlackPWM.h, BlackSPI.cpp, BlackSPI.h, BlackUART.cpp, BlackUART.h
3) open following files in Code::Blocks BlackUART.cpp, BlackSPI.cpp, BlackI2C.cpp and add
#include <unistd.h>
right after #include "BlackUART.h", the "unistd.h" includes all the functions like sleep(), open(), close(), ... that otherwise seems missing
4) create your own program main.cpp, you may use the following code for testing UART1 and UART2:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sstream>
#include <string>
#include <iostream>
#include "BlackLib.h"
int main(){
std::string writeToUart1;
std::string writeToUart2;
std::string readFromUart1;
std::string readFromUart2;
int counter;
std::ostringstream os1;
std::ostringstream os2;
BlackLib::BlackUART Uart1(BlackLib::UART1,
BlackLib::Baud9600,
BlackLib::ParityEven,
BlackLib::StopOne,
BlackLib::Char8 );
// Pins on BeagleBone Black REV C
// UART1_RX -> GPIO_15 (P9.24)
// UART1_RX -> GPIO_14 (P9.26)
BlackLib::BlackUART Uart2(BlackLib::UART2,
BlackLib::Baud9600,
BlackLib::ParityEven,
BlackLib::StopOne,
BlackLib::Char8 );
// Pins on BeagleBone Black REV C
// UART2_RX -> GPIO_2 (P9.22)
// UART2_RX -> GPIO_3 (P9.21)
std::cout << "Program UART start" << std::endl << std::flush;
Uart1.open( BlackLib::ReadWrite | BlackLib::NonBlock );
Uart2.open( BlackLib::ReadWrite | BlackLib::NonBlock );
counter = 0;
while (true){
os1.str("");
os1.clear();
os1 << "Uart1 to TX: " << counter << "\n";
writeToUart1 = os1.str();
Uart1 << writeToUart1;
readFromUart1 = "";
Uart1 >> readFromUart1;
if (readFromUart1.compare("") != 0){
std::cout << "Uart1 from RX: " << readFromUart1 << "\n" << std::flush;
}
Uart1.flush( BlackLib::bothDirection );
counter++;
sleep(2);
os2.str("");
os2.clear();
os2 << "Uart2 to TX: " << counter << "\n";
writeToUart2 = os2.str();
Uart2 << writeToUart2;
readFromUart2 = "";
Uart2 >> readFromUart2;
if (readFromUart2.compare("") != 0){
std::cout << "Uart2 from RX: " << readFromUart2 << "\n" << std::flush;
}
Uart2.flush( BlackLib::bothDirection );
counter++;
sleep(2);
}
return 1;
}
5) save the main.cpp to the same folder as the BlackLib files
6) using WinSCP, create directory on the BBB (e.g. /home/uart) and copy all the BlackLib files and main.cpp into this folder
7) open Putty and navigate to the folder by :
cd /home/uart
8) compile the files by using :
gcc *.cpp -o main -std=c++11
9) run the program :
./main
10) connect the wires to UART<->USB converter and BBB. The ouput from BBB should look like :
Uart2 to TX: 1 OR Uart1 to TX: 0
Uart2 to TX: 3 OR Uart1 to TX: 2
depending on connection of wires
It seems I managed to fix it myself, some nooblike behaviour not including all the cpp files, but even more, I also needed to add #include to BlackCore.h to avoid tons of undefined function errors.
final command:
g++ exampleAndTiming.cpp exampleAndTiming/Timing.cpp BlackADC.cpp BlackCore.cpp BlackGPIO.cpp BlackI2C.cpp BlackPWM.cpp BlackSPI.cpp BlackUART.cpp -std=c++11
I'd probably need to make a makefile to compile the library seperately, time to do some more digging and learning.
I am the creator of BlackLib, Yiğit YÜCE. You found your answer by yourself. The makefile which you mentioned on your comment will be published shortly.

Segmentation fault in a very simple qt app that uses ffmpeg

I'm quite new on C++ and QT, but I did manage to set up my environment to compile and link against ffmpeg (I downloaded and installed this Version "Qt 5.1.1 for Windows 32-bit (MinGW 4.8, OpenGL, 666 MB)" and the latest ffmpeg shared libs (FFmpeg 32-bit Shared Versions, FFmpeg 32-bit Dev Versions from http://ffmpeg.zeranoe.com/builds/)
I have this simple app:
#include "frmmain.h"
#include "ui_frmmain.h"
#define __STDC_CONSTANT_MACROS
namespace ffmpeg
{
extern "C"
{
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
}
}
frmMain::frmMain(QWidget *parent) :
QDialog(parent),
ui(new Ui::frmMain)
{
ui->setupUi(this);
ffmpeg::avcodec_register_all();
ffmpeg::AVFormatContext *pFormatCtx;
if ((ffmpeg::avformat_open_input(&pFormatCtx,"d:\\1.wmv" , NULL, NULL)) < 0)
{
printf("could not open the file");
}
}
frmMain::~frmMain()
{
delete ui;
}
The build process runns with no errors, but if I debug the project I get an Segmentation fault
If I run the project it just crashes without any message.
Any ideas what I'm doing wrong?
Thanks in advance
easy one :)
ffmpeg::AVFormatContext *pFormatCtx = NULL;

"Access violation" Error on displaying string of simple Oracle Query (VS10 Exp C++)

I am struggling with an issue regarding running a SQL statement to an Oracle database through C++, using occi. My code is as follows:
#include <iostream>
#include "occi.h"
namespace oc = oracle::occi;
int main() {
std::cout << "Setting up environment...\n";
oc::Environment * env = oc::Environment::createEnvironment();
std::cout << "Setting up connection...\n";
oc::Connection * conn = env->createConnection("user","pass","server");
std::cout << "Creating statement...\n";
//Very simply query...
oc::Statement * stmt = conn->createStatement("SELECT '1' FROM dual");
std::cout << "Executing query...\n";
oc::ResultSet * rs = stmt->executeQuery();
while(rs->next()) {
std::cout << rs->getString(1) << std::endl; //Error is thrown at this line, but after printing since I can see '1' on the console.
}
stmt->closeResultSet(rs);
conn->terminateStatement(stmt);
env->terminateConnection(conn);
oc::Environment::terminateEnvironment(env);
return 0;
}
The error that is shown is:
Unhandled exception at 0x1048ad7a (msvcp100d.dll) in MyDatabaseApp.exe: 0xC0000005: Access violation reading location 0xccccccd0.
My program stops inside 'xstring' at the following line of code:
#if _ITERATOR_DEBUG_LEVEL == 0
....
#else /* _ITERATOR_DEBUG_LEVEL == 0 */
typedef typename _Alloc::template rebind<_Elem>::other _Alty;
_String_val(_Alty _Al = _Alty())
: _Alval(_Al)
{ // construct allocator from _Al
....
}
~_String_val()
{ // destroy the object
typename _Alloc::template rebind<_Container_proxy>::other
_Alproxy(_Alval);
this->_Orphan_all(); //<----------------------Code stops here
_Dest_val(_Alproxy, this->_Myproxy);
_Alproxy.deallocate(this->_Myproxy, 1);
this->_Myproxy = 0;
}
#endif /* _ITERATOR_DEBUG_LEVEL == 0 */
If I change my query to:
oc::Statement * stmt = conn->createStatement("SELECT 1 FROM dual");
and the loop statement to:
std::cout << rs->getInt(1) << std::endl;
It works fine with no errors. I think this is because getting an integer simply returns a primitive, but when an object is being returned it is blowing up (I think on a destructor, but I'm not sure why...)
I have been playing around with this for hours today, and I am pretty stuck.
Some information about my system:
OS - Windows XP
Oracle Version - 10g
IDE - Microsoft Visual Studio 2010 Express C++
My project properties are as follows:
C/C++ - General - Additional Include Directories = C:\oracle\product\10.2.0\client_1\oci\include;%(AdditionalIncludeDirectories)
C/C++ - Code Generation - Multi-threaded Debug DLL (/MDd)
Linker - General - Additional Library Directories = C:\oracle\product\10.2.0\client_1\oci\lib\msvc\vc8;%(AdditionalLibraryDirectories)
Linked - Input - Additional Dependencies = oraocci10.lib;oraocci10d.lib;%(AdditionalDependencies)
I hope I haven't been confusing with too much info... Any help or insight would be great, Thanks in advance!
EDIT If I rewrite my loop, storing the value in a local variable, the error is thrown at the end of the loop:
while(rs->next()) {
std::string s = rs->getString(1); //s is equal to "1" as expected
std::cout << s << std::endl; //This is executed successfully
} //Error is thrown here
Usually such kind of problems come from differences in build environments (IDE) of end user and provider.
Check this.
Related problems:
Unhandled exception at 0x523d14cf (msvcr100d.dll)?
Why does this program crash: passing of std::string between DLLs
First try to use correct lib and dll. If compiled in debug mode then all libs and dlls must be debug. Use VC++ Modules view to be sure that proper DLL loaded.
I was lucky with my application to have all libs compiled for MSVC2010. So I just check debug and release mode DLLs and got working application.
I revisited this issue about a month ago and I found that the MSVC2010 occi library was built for Oracle 11g. We are running Oracle 10g, so I had to use the MSVC2005 library. So I installed the outdated IDE and loaded the Debug library and it worked (for some reason the release version wouldn't work though).
EDIT
For anyone who is having the same problem I was, if downgrading the IDE from MSVC2010 to MSVC2005 with the appropriate libraries doesn't work, you could try upgrading the Oracle client from 10g to 11g and use the MSVC2010 library, as suggested by harvyS. In retrospect this would've probably been the better solution.