undefined reference to `_imp___ZN15QSerialPortInfo14availablePortsEv' - qt

I am working on simple app on windows to scan the serial port.
Error:
undefined reference to `_imp___ZN15QSerialPortInfo14availablePortsEv'
My Code:
foreach(const QSerialPortInfo &info, QSerialPortInfo::availablePorts()) {
// do something
}
What does the error mean and how to fix it.

i only needed to add QT += serialport in my project (appname.pro) file.

Related

Visual Studio not compiling

I am trying to compile my code. If I compile it in Arduino IDE it works, but if I try it in Visual Studio 2019 it fails.
I am trying to use a struct as a parameter.
I have tried pointer and typedef, but get the same error
I can compile it in Arduino IDE, but the same code gets this error in VS 2019:
Compiling debug version of 'test' for 'ATmega2560 (Mega 2560) (Arduino Mega)'
test.ino: 7:17: error: variable or field 'myFunction' declared void
Error compiling project sources
Debug build failed for project 'test'
test.ino: 7:17: error: 'data' was not declared in this scope
test.ino:7: note suggested alternative atan
atan
struct data{
float data;
};
data data_struct;
void myFunction(data data_struct){
}
int main(){}
You did not provide a declaration for myFunction. That's done by the Arduino IDE behind the scenes.
Try:
struct data{
float data;
};
data data_struct;
void myFunction(data data_struct);
void myFunction(data data_struct){
}
int main(){}

How to get name of WiFi using QT quick application on Android

I am trying to develop a code to get name of wifi connected to my android phone. My code sample is
QStringList WiFisList;
QNetworkConfiguration cfg;
QNetworkConfigurationManager ncm;
auto nc = ncm.allConfigurations();
for (auto &x : nc)
{
qDebug()<< "CHECK1 " << x.bearerType();
if (x.bearerType() == QNetworkConfiguration::BearerWLAN)
{ qDebug ()<<"CHECK2";
qDebug() <<"WIFI is"<<x.name();
}
}
Output of this code is just returning me:
(int main(int, char)): WIFI is "WiFi" but my expected output is ASUS_XOOTD
How can I get this as output? Is something missing in my code?
check that your qt version is supporting Bearer extension for android.

Error while connecting lambda function to QProcess::error

In following code I want to connect lambda function to QProcess::error signal:
void Updater::start() {
QProcess process;
QObject::connect(&process, &QProcess::error, [=] (QProcess::ProcessError error) {
qWarning() << "error " << error;
});
process.start("MyProgram");
process.waitForFinished();
}
But I get strange error:
error: no matching function for call to 'Updater::connect(QProcess*
[unresolved overloaded function type],
Updater::start()::)' });
What I do wrong here? The code executes inside method of class derived from QObject. The project configured to work with c++11.
I use Qt 5.3.1 on Linux x32 with gcc 4.9.2
Problem is that the QProcess has another error() method, so compiler just doesn't know which method use. If you want to deal with overloaded methods, you should use next:
QProcess process;
connect(&process, static_cast<void (QProcess::*)(QProcess::ProcessError)>
(&QProcess::error), [=](QProcess::ProcessError pError) {
qWarning() << "error " << pError;
});
process.start("MyProgram");
process.waitForFinished();
Yes, it looks ugly, but there is no another way (only old syntax?).
This special line tells compiler that you want to use void QProcess::error(QProcess::ProcessError error), so now there is no any ambiguity
More information you can find here.
For those who are using Qt 5.6 or later, the QProcess::error signal is deprecated. You can use the QProcess::errorOccurred signal instead to avoid the naming ambiguity and complicated casting.
QProcess process;
connect(&process, &QProcess::errorOccurred, [=](QProcess::ProcessError error) {
qWarning() << error;
});
process.start("MyProgram");
process.waitForFinished();

QSslSocket: cannot resolve SSLV2_client_method

I have created a sslclient and sslserver using QSslSocket in Qt 5.4.1 in debian wheezy. When I run the program they dont work at all. After debuging my code I saw when it try to create a new object from QSslSocket it return this error (cannot resolve SSLV2_client_method) in constractor.
this is block of my code:
SSlClient::SSlClient(QObject *parent) : QObject(parent)
{
client = new QSslSocket(this);
client->setProtocol(QSsl::SslV3);
connect(client, SIGNAL(encrypted()), this, SLOT(startTransfer()));
connect(client, SIGNAL(encryptedBytesWritten(qint64)), this, SLOT(byteWritten()));
}
The problem has solved by compiling openssl as shared library.

Qt: How to use an accesspoint throughout the application?

I'm developing an application for Symbian S60 phones using the Qt Nokia SDK, which sends requests and receives responses from a webservice in every view i have.
The problem with this, is that it always asks the user to choose a accesspoint.
So what i want is to choose an accesspoint when the application starts, and use that throughout the application.
So i found this example: http://wiki.forum.nokia.com/index.php/How_to_set_default_access_point_using_Qt_Mobility_APIs
but i got following error:
undefined reference to 'QtMobility::QNetworkConfigurationManager::QNetworkConfigurationManager(QObject*)
i'm also getting more of these errors from other classes from QMobillity, like:
undefined reference to 'QtMobility::QNetworkSession::open()
.pro file:
CONFIG += mobility
MOBILITY += bearer
header:
#include <qmobilityglobal.h>
#include <QtNetwork>
#include <QNetworkSession>
#include <QNetworkConfigurationManager>
QTM_USE_NAMESPACE;
cpp file:
QNetworkConfigurationManager manager;
const bool selectIap = (manager.capabilities()& QNetworkConfigurationManager::CanStartAndStopInterfaces);
QNetworkConfiguration defaultIap = manager.defaultConfiguration();
if(!defaultIap.isValid() && (!selectIap && defaultIap.state() != QNetworkConfiguration::Active))
{
qDebug() << "Network access point NOT found";
// let the user know that there is no access point available
msgBox->setText(tr("Error"));
msgBox->setInformativeText(tr("No default access point available"));
msgBox->setStandardButtons(QMessageBox::Ok);
msgBox->setDefaultButton(QMessageBox::Ok);
msgBox->topLevelWidget();
msgBox->exec();
}
else
{
qDebug() << "Network access point found and chosen";
}
session = new QNetworkSession(defaultIap,this);
session->open();
Anyone got an idea of what could be wrong?
Have you tried adding this to the .PRO file?
CONFIG += network

Resources