Compiler complaining undefined reference to std::thread::_State::~_State() when I am trying to create RSA_PrivateKey object in Botan C++.
#include <QCoreApplication>
#include <botan/rsa.h>
#include <botan/auto_rng.h>
#include <iostream>
using std::cout;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
std::unique_ptr<Botan::RandomNumberGenerator> rng(new Botan::AutoSeeded_RNG);
cout << rng->name();
// this line caused the error
std::unique_ptr<Botan::RSA_PrivateKey> theKey(new Botan::RSA_PrivateKey(*rng.get(),1024));
return a.exec();
}
Error shows like this:
Error when creating RSA_PrivateKey in Botan
I'm really not sure why the compiler is complaining. I need help, thanks in advance.
I added the botan library as a static library using the ".a" file. I did it by right-clicking the project folder > add library > External Library. I tried to compile in debug.
Added botan like this
OS: Windows 7
Compiler:Qt 5.11.2 MinGW 32-bit
You should create an instance of Botan::RSA_PrivateKey :
Botan::RSA_PrivateKey rsa(*rng.get(),1024);
I'm trying to create an app that connects to my local MySql through XAMPP and outputs the data into a tableWidget.
After writing all the code for it and correcting all the mistakes, I'm getting 17 errors about "undefined reference to `_imp__ZN.....' "
1st Question: Do I have to put all my project files inside XAMPP/htdocs like I did using PHP?
2nd Question: I've only written something inside main.cpp, did I miss something for other classes or maybe I need something else inside the header file?
I've heard that "imp_" problems are related to the compiler, but I'm not sure what to do!
Without further ado, this is my main.cpp:
#include "mainwindow.h"
#include <QApplication>
#include <QtSql/QSql>
#include <QtGui/QtGui>
#include <QMessageBox>
#include <QtSql/QSqlDatabase>
#include <QTableWidget>
#include <QtSql/QSqlError>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QTableWidget* tableWidget = new QTableWidget();
tableWidget->setWindowTitle("Connect to Mysql Database");
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("localhost");
db.setDatabaseName("pizzeria mabo");
db.setUserName("root");
db.setPassword("");
if (!db.open())
{
QSqlError err = db.lastError();
QMessageBox::critical(0, QObject::tr("Database Error"), err.text());
}
MainWindow w;
w.show();
return a.exec();
}
And here are my errors:
http://i57.tinypic.com/nodow7.png
Thank you for your help!
Well, the errors mean that you are missing a library containing the necessary symbols. If you are using qmake to build the project you have to enable SQL via "QT += sql". Otherwise you will have to find and add the library manually.
I would like to ask if you could help me with my app.
I have an application in C++ using Qt (and Qwt) in MCVS 2010. I want to open QDialog window with QwtPlot on button click from Main Window (QMainWindow). Here is some code:
MainWindow.cpp
void MainWindow::on_pushButton_1_clicked ()
{
Dialog_plot dp;
dp.setModal(true);
dp.exec();
}
Dialog_plot.cpp:
#include <qwt_plot.h>
#include <qwt_plot_canvas.h>
#include <qwt_plot_curve.h>
#include "Dialog_plot.h"
Dialog_plot::Dialog_plot(QWidget *parent)
{
plot = new QwtPlot();
//more code...
main.cpp:
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
This code is compiling, but when I click on that pushbutton_1 in my application I'm getting error:
Must construct a QApplication before a QPaintDevice
I know that such error was discussed many times and I was reading a lot about it but I can't see solution for my problem.
One more thing I would like to mention - I have similar application with Qwt plot written by somebody else and his application compiles and works without any problems in my MCVS. I was trying to compare Linker/libraries included but it seems to be the same. So I guess there is a problem with my application, I just can't solve it. I really need some help!
I was trying to create a simple console application to try out Qt's XML parser. I started a project in VS2008 and got this template:
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
return a.exec();
}
Since I don't need event processing, I was wondering whether I may get into trouble if I neglect to create a QCoreApplication and running the event loop. The docs state that it's recommended in most cases.
For the sake of curiosity however, I am wondering how could I make some generic task execute on the event loop and then terminate the application. I was unable to google a relevant example.
Here is one simple way you could structure an application if you want an event loop running.
// main.cpp
#include <QtCore>
class Task : public QObject
{
Q_OBJECT
public:
Task(QObject *parent = 0) : QObject(parent) {}
public slots:
void run()
{
// Do processing here
emit finished();
}
signals:
void finished();
};
#include "main.moc"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
// Task parented to the application so that it
// will be deleted by the application.
Task *task = new Task(&a);
// This will cause the application to exit when
// the task signals finished.
QObject::connect(task, SIGNAL(finished()), &a, SLOT(quit()));
// This will run the task from the application event loop.
QTimer::singleShot(0, task, SLOT(run()));
return a.exec();
}
Don't forget to add the
CONFIG += console
flag in the qmake .pro file.
For the rest is just using some of Qt classes.
One way I use it is to spawn processes cross-platform.
You don't need the QCoreApplication at all, just include your Qt objects as you would other objects, for example:
#include <QtCore>
int main()
{
QVector<int> a; // Qt object
for (int i=0; i<10; i++)
{
a.append(i);
}
/* manipulate a here */
return 0;
}
I managed to create a simple console "hello world" with QT Creator
used creator 2.4.1 and QT 4.8.0 on windows 7
two ways to do this
Plain C++
do the following
File- new file project
under projects select : other Project
select "Plain C++ Project"
enter project name
5.Targets select Desktop 'tick it'
project managment just click next
you can use c++ commands as normal c++
or
QT Console
File- new file project
under projects select : other Project
select QT Console Application
Targets select Desktop 'tick it'
project managment just click next
add the following lines (all the C++ includes you need)
add "#include 'iostream' "
add "using namespace std; "
after QCoreApplication a(int argc, cghar *argv[])
10 add variables, and your program code..
example: for QT console "hello world"
file - new file project 'project name '
other projects - QT Console Application
Targets select 'Desktop'
project management - next
code:
#include <QtCore/QCoreApplication>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
cout<<" hello world";
return a.exec();
}
ctrl -R to run
compilers used for above MSVC 2010 (QT SDK) , and minGW(QT SDK)
hope this helps someone
As I have just started to use QT recently and also searched the Www for info and examples to get started with simple examples still searching...
You could fire an event into the quit() slot of your application even without connect().
This way, the event-loop does at least one turn and should process the events within your main()-logic:
#include <QCoreApplication>
#include <QTimer>
int main(int argc, char *argv[])
{
QCoreApplication app( argc, argv );
// do your thing, once
QTimer::singleShot( 0, &app, &QCoreApplication::quit );
return app.exec();
}
Don't forget to place CONFIG += console in your .pro-file, or set consoleApplication: true in your .qbs Project.CppApplication.
You can call QCoreApplication::exit(0) to exit with code 0
Had the same problem. found some videos on Youtube.
So here is an even simpler suggestion. This is all the code you need:
#include <QDebug>
int main(int argc, char *argv[])
{
qDebug() <<"Hello World"<< endl;
return 0;
}
The above code comes from
Qt5 Tutorial: Building a simple Console application by
Dominique Thiebaut
http://www.youtube.com/watch?v=1_aF6o6t-J4
I have experience with C++ but I've never really used Qt before. I'm trying to connect to a SQLite database, so I found a tutorial here and am going with that. In the QtCreator IDE, I went to Add New --> C++ Class and in the header file pasted in the header the header from that link and in the .cpp file I pasted the source. My main.cpp looks like this:
#include <QtGui/QApplication>
#include "mainwindow.h"
#include "databasemanager.h"
#include <qlabel.h>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
DatabaseManager db();
QLabel hello("nothing...");
if(db.openDB()){ // Line 13
hello.setText("Win!");
}
else{
hello.setText("Lame!");
}
hello.resize(100, 30);
hello.show();
return a.exec();
}
And I'm getting this error:
main.cpp:13: error: request for member 'openDB' in 'db', which is of non-class type 'DatabaseManager()'
Can anyone point me in the right direction? I know "copypaste" code isn't good, I just wanted to see if I could get DB connectivity working and I figured something like this would be simple... thanks for the help.
Change the DatabaseManager line to:
DatabaseManager db;
You're declaring a local function called db that takes no parameters and returns a DatabaseManager object when you provide the ();