QSQLITE driver not loaded - qt

I'm creating a light APP with QT that add entries into my SQLITE base from my website.
But I've this problem :
("QSQLITE")
QSqlError(-1, "", "")
DATABASE OPENED
QSqlQuery::prepare: database not open
QSqlError(-1, "Driver not loaded", "Driver not loaded")
I'm on a Bananapi (Debian 7) with QT installed and upgrade from Debian-APT.
This is my code :
// Load QSLite driver
qDebug() << bdd.drivers(); //Said : ("QSQLITE")
bdd = QSqlDatabase::addDatabase("QSQLITE");
qDebug() << bdd.lastError();
// Open the database
bdd.setDatabaseName("/var/www/config/database.sqlite");
// Connect to the database
if( ! bdd.open())
{
qDebug() << "ERROR " << EXIT_FAILURE_CANT_OPEN_DATABASE << " : Can't open database";
qDebug() << bdd.lastError();
exit(EXIT_FAILURE_CANT_OPEN_DATABASE);
}
else
qDebug() << "DATABASE OPENED";
query.prepare(....); //Said : QSqlQuery::prepare: database not open.
Any idea ?

Related

SQLITE c++ in Visual Studio

#include <iostream>
#include <SQLiteCpp/SQLiteCpp.h>
#include <SQLiteCpp/VariadicBind.h>
int main() {
std::cout << "SQlite3 version " << SQLite::VERSION << " (" << SQLite::getLibVersion() << ")" << std::endl;
std::cout << "SQliteC++ version " << SQLITECPP_VERSION << std::endl;
try {
SQLite::Database db("my.db3", SQLite::OPEN_READWRITE | SQLite::OPEN_CREATE);
std::cout << "SQLite database file '" << db.getFilename().c_str() << "' opened successfully\n";
}
}
On debugging it shows the error saying "Unable to start the program 'C:\SQLITE\SQLITE\x64\Debug\SQLite.exe' - The system cannot find the file specified"
I am not sure what to do in this case.
I am trying to create a sql database and create a table on it and make a relation table out of the tables that I will be creating. But I am not able to create a database due to this issue and cannot move forward with my task

Problems with OpenCL helloworld

i´m new to OpenCl and i´m trying to learn it right know.
I installed Intel® SDK for OpenCL™ Applications and now i´m trying to use it with visual studio 2015.
When i´m trying to run an hello world example it returns an error at the "program.build" -part in the following codepart.
Can somebody tell me what i´m missing?
Thanks :)
The consol returns this:
Using platform: Intel<R> OpenCL
Using device: Intel<R> Core<TM> i7-3770 CPU e 3.40 GHz
-44
Error building:
Examplecode:
//get all platforms (drivers)
std::vector<cl::Platform> all_platforms;
cl::Platform::get(&all_platforms);
if (all_platforms.size() == 0) {
std::cout << " No platforms found. Check OpenCL installation!\n";
exit(1);
}
cl::Platform default_platform = all_platforms[0];
std::cout << "Using platform: " << default_platform.getInfo<CL_PLATFORM_NAME>() << "\n";
//get default device of the default platform
std::vector<cl::Device> all_devices;
default_platform.getDevices(CL_DEVICE_TYPE_ALL, &all_devices);
if (all_devices.size() == 0) {
std::cout << " No devices found. Check OpenCL installation!\n";
exit(1);
}
cl::Device default_device = all_devices[0];
std::cout << "Using device: " << default_device.getInfo<CL_DEVICE_NAME>() << "\n";
cl::Context context({ default_device });
cl::Program::Sources sources;
// kernel calculates for each element C=A+B
std::string kernel_code =
" void kernel simple_add(global const int* A, global const int* B, global int* C){ "
" C[get_global_id(0)]=A[get_global_id(0)]+B[get_global_id(0)]; "
" } ";
sources.push_back({ kernel_code.c_str(),kernel_code.length() });
cl::Program program(context, sources);
if (**program.build({ default_device }) != CL_SUCCESS**) {
std::cout << program.build({ default_device }) <<"\n";
std::cout << " Error building: " << program.getBuildInfo<CL_PROGRAM_BUILD_LOG>(default_device) << "\n";
exit(1);
}
Error code -44 means that "the program object is invalid". However this is inconclusive and hints to some other issue that corrupts memory. Also see this question.
Calling program.build() twice is - although not good practice - not the issue here, but maybe some threading issues? The problem certainly is not in the code snipped you provided.

QSqlDatabase not opening

I am unable to understand what I am doing wrong here. I am using Qt 5.7.1 and the code is as follows:
QString filePath = QCoreApplication::applicationDirPath();
QString dbPath = QDir(filePath).absoluteFilePath("../../../Database");
m_db = QSqlDatabase::addDatabase("QSQLITE", "user_connection");
m_db.setDatabaseName(dbPath + "/Sensor_Objects.db");
qDebug() << filePath << " & " << dbPath;
if (!m_db.open())
qDebug() << "Database Error: " + m_db.lastError().text();
else
{
qDebug() << "Database: connection ok";
createDatabase("Sensor_Objects");
m_db.close();
}
qDebug() is printing the paths to the directories correctly and yet m_db.open() fails with the error "Database Error: out of memory Error opening database".
Probably the point is dbpath,try with
m_db.setDatabaseName(dbPath.toLatin1() + "/Sensor_Objects.db");

Strange reply when uploading zip file to amazon S3 using REST ,QT and PUT request

iam trying to upload zip file to S3 amazon but i have problem.
i am using QT : sending request and receiving reply.
i am sending the URL with zip file here is the code :
QFile *file = new QFile(fileName);
QString fileSize = QString::number(file->size());
file->open(QIODevice::ReadOnly);
QByteArray data(file->readAll());
QNetworkRequest req;
QNetworkReply* rep;
req.setUrl(QUrl(url /*cant post the real URL*/));
req.setRawHeader(QString("Content-Length").toUtf8(), fileSize.toUtf8());
rep = m_manager->post(req, data);
connect(rep, SIGNAL(finished()), &loop, SLOT(quit()));
loop.exec();
CheckReply(rep);
and here is CheckReply function
bool CheckReply(QNetworkReply *reply)
{
if (reply->error())
{
qDebug() << "ERROR!";
qDebug() << reply->errorString();
return false;
}
else
{
qDebug() << reply->header(QNetworkRequest::ContentTypeHeader).toString();
qDebug() << reply->header(QNetworkRequest::LastModifiedHeader).toDateTime().toString();
qDebug() << reply->header(QNetworkRequest::ContentLengthHeader).toULongLong();
qDebug() << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
qDebug() << reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString();
return true;
}
}
the problem is , CheckReply() shows this msg : "Error downloading -request URL-".
why this happens , it is upload NOT download.
thanks
OK i find the problem , in case any one face the same problem.
the bug was that i use QUrl(QSting) , to set the request url.
instead of that use this : QUrl::fromEncoded(QByteArray) or
QUrl::fromEncoded(/your QString/.toUtf8()).

Sqlite3 network oddity

I have a simple QT program to read an sqlite3 database. Annoyingly, my program failed when the actual database is on the network as a mapped drive (Windows 7) but works when the database is on the local drive. The code I'm using is below and just for experimental purposes.
QFileInfo fileInfo(m_lastDatabaseFile);
QString host = fileInfo.canonicalPath();
QString filename = fileInfo.fileName();
m_dataBase = QSqlDatabase::addDatabase("QSQLITE");
m_dataBase.setHostName(host);
m_dataBase.setDatabaseName(filename);
qDebug() << " valid: " << m_dataBase.isValid();
if (m_dataBase.open() )
{
QStringList tableList = m_dataBase.tables(QSql::Tables);
qDebug() << "Database open.";
QSqlQuery query = m_dataBase.exec("SELECT * FROM PallolBoards");
qDebug() << "Found: " << query.size();
if (query.size() <= 0)
{
QSqlError err = query.lastError();
qDebug() << "Last error: " << err.text();
}
while (query.next() )
{
QString title = query.value(0).toString();
qDebug() << "Query: " << title;
}
}
else
{
QMessageBox::critical(this,"Invalid database",m_dataBase.lastError().text());
}
Any clues anyone? So H: will fail but D: succeeds.
At least in windows vista there was a security setting controlling if an application was allowed to access network shares or not.
There is also a dependency between Internet security settings(accessible through e.g. internet explorer) and access to network shares.

Resources