#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
Related
I got this code from a book. When I ran on Visual Studio, it said to switch strcpy() to strcpy_s(), and after I did that, it seems the program terminated at the delete pointer. I tried to run on Dev-C++, and it works fine. Anyone knows why? Thank you.
#include "pch.h"
#include <iostream>
#include <cstring>
int main()
{
cout << "Enter a kind of animal: ";
cin >> animal; // ok if input < 20 chars
ps = animal; // set ps to point to string
cout << ps << "!\n"; // ok, same as using animal
cout << "Before using strcpy():\n";
cout << animal << " at " << (int *)animal << endl;
cout << ps << " at " << (int *)ps << endl;
ps = new char[strlen(animal) + 1]; // get new storage
strcpy_s(ps, sizeof(animal), animal); // copy string to new storage
cout << "After using strcpy():\n";
cout << animal << " at " << (int *)animal << endl;
cout << ps << " at " << (int *)ps << endl;
delete[] ps;
return 0;
}
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.
I created a QMediaPlayer, passed video address to it and it won't play. I checked the mediaStatus and player state, they all stays 0 all the time. The basic idea is:
QMediaPlayer player = new QMediaPlayer();
cout << player.mediaStatus(); // should print 1: NoMedia but is 0: UnknownMediaStatus
player.setVideoOutput(some_constructed_video_widget);
cout << player.mediaStatus(); // should print 1: NoMedia but is 0: UnknownMediaStatus
player.setMedia(QUrl::fromLocalFile("path/to/test/video/test.mp4"));
cout << player.mediaStatus(); // should print 2: LoadingMedia but is 0: UnknownMediaStatus
player.play();
cout << player.mediaStatus(); // should print 3: LoadedMedia but is 0: UnknownMediaStatus
// and of course, no video gets played
The mediaStatus is simply a enum: MediaStatus { UnknownMediaStatus, NoMedia, LoadingMedia, LoadedMedia, ..., InvalidMedia }
The questions are:
What may be causing this problem and how to fix that?
What are all the cases that a QMediaPlayer::mediaStatus() will return an QMediaPlayer::UnknownMediaStatus (please be conclusive)?
Edit with more information: The following is the output I get for the following code. Anyone has any idea what the error message means and how to fix that?
code:
int main(int argc, char *argv[])
{
QMediaPlayer * temp = new QMediaPlayer(0, QMediaPlayer::VideoSurface);
std::cout << "Constructed: " << temp->mediaStatus() << std::endl;
temp->setMedia(QUrl::fromLocalFile("path/to/video/test.mp4"));
std::cout << "SetMedia: " << temp->mediaStatus() << std::endl;
temp->play();
std::cout << "Play: " << temp->mediaStatus() << std::endl;
-> debug breakpoint here
......
}
output:
defaultServiceProvider::requestService(): no service found for - "org.qt-project.qt.mediaplayer"
Constructed: 0
SetMedia: 0
Play: 0
I am using Mac 10.9 and Qt 5.3.0, but I do not think the mac/qt version matters for this problem.
I'm somewhat new to C++ and QT.
Trying to run a very simple program in QtCreator, which uses console input on WinXP:
#include <QString>
#include <QTextStream>
int main() {
QTextStream streamOut(stdout);
QTextStream streamIn(stdin);
QString s1("This "), s2("is a "), s3("string.");
QString s4 = s1 + s2 + s3;
streamOut << s4 << endl;
streamOut << "The length of that string is " << s4.length() << endl;
streamOut << "Enter a sentence with whitespaces: " << endl;
s4 = streamIn.readLine();
streamOut << "Here is your sentence: \n" << s4 << endl;
streamOut << "The length of your sentence is: " << s4.length() << endl;
return 0;
}
Problem is that native QTCreator's application output, for it's name, doesn't support typing in things. Here is application output:
Starting C:\QProject\test-build-desktop-Qt_4_8_0_for_Desktop_-MinGW_Qt_SDK___>z>>\debug\test.exe...
This is a string.
The length of that string is 17
Enter a sentence with whitespaces:
Qml debugging is enabled. Only use this in a safe environment!
I've tried checking "Run in terminal" in Projects>Desktop>Run as some answers to similar questions here suggested and the terminal shows up, but it doesn't seem to interact with the program anyhow. Terminal's output:
Press RETURN to close this window...
I would say that checking Run in terminal is correct and needed.
What is surprising is that you don't get any compile error, as there is a mistake at line 8 :
cout << "Enter a sentence: "<<;
The last << is wrong.
Correcting your code, I get this :
#include <QString>
#include <QTextStream>
QTextStream cout(stdout);
QTextStream cin(stdin);
int main() {
QString s2;
cout << "Enter a sentence: ";
s2 = cin.readLine();
cout << "Here is your sentence:" << s2 << endl;
cout << "The length of your sentence is: " << s2.length() << endl;
return 0;
}
which works fine on my computer (WinXP, QtCreator 2.2.0).
Are you sure your Qt project is correct and that you are compiling the right file ?
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.