I'm using the pleora sdk to capture images from an external camera and I am able to successfully write the data to tiff image files on disk. My next step is to change the data storage to SQLite instead of disk files.
I have PvBuffer *lBuffer pointer working fine. Now I need to convert that data to a format I can use to write to SQLite. I'm using Qt on linux so the QByteArray would be very convenient.
This is kind of a specific question for the pleora sdk and Qt. I'm hoping someone has experience with this.
PvRawData *rawData = lBuffer->GetRawData();
QByteArray ba;
//Need to copy the data from rawData to ba.
Thank you in advance.
I found an answer and wanted to post in case anybody else has something similar. I uses the reintepret_cast method.
data = lBuffer->GetDataPointer()
imgSize = lBuffer->GetPayloadSize();
const char *d = reinterpret_cast<char *>(data);
QByteArray ba(d, imgSize);
QSqlQuery q = QSqlQuery( db );
q.prepare("INSERT INTO imgData (image) values (:imageData)");
q.bindValue(":imageData", ba);
if ( !q.exec() )
qDebug() << "Error inserting image into table: " << q.lastError() << endl;
else
qDebug() << "Query executed properly" << endl;
Related
I'm trying to create a simple "To Do list" app in QT Creator while coding the part that loads and saves the list from a file I get stuck on a problem.
If you enter a string like "Do my homework" the program threads the string as it should, but when you load the program again the save file got split in words. So it gets all the entries but each word separated ("Do", "my", "homework").
What is the solution? I tried working with 'char arrays' and 'getline' but they give me nothing but errors.
Here is my code for the save and load parts:
void MainWindow::LoadList(){
std::ifstream load_file("./data.bin");
char loader[255];
while (load_file >> loader){
QString Writer = QString::fromStdString(loader);
ui->lstTaskList->addItem(Writer);
}
}
void MainWindow::SaveList(){
std::ofstream save_file("./data.bin");
for (auto i = 0; i < ui->lstTaskList->count(); i++){
QString Saver = ui->lstTaskList->item(i)->text();
std::string saver = Saver.toStdString();
save_file << saver << std::endl;
}
}
Can anyone help me with this, please?
My thanks in advance...
The anwser was using QFile and QByteArray for me, I knew about QFile but it tries using basic "std" c++ till I learned more about QT.
I am writing a plugin for a Qt desktop app using PythonQT.
I wonder how to use << operator in python.
QTextStream stream(&file);
stream << doc.toString();
Any hints?
How may I ask Python to list all methods for a given class like QTextStream?
Or is there another way in Python to write a QDomDocument to a QFile?
Found a solution already...
doc = QDomDocument()
root = doc.createElement("Animation")
doc.appendChild(root)
stream = QTextStream(xmlfile)
doc.save(stream, 0)
I'm creating a music player for PC. I want to visualize the FFT of the song. I've crated an entire class that buffers 1024 points of data does the FFT and displays it (this is handled by another class). My program was developed in my laptop which uses Debian Testing x64. My work pc uses Centos 7 x64. When I compiled my program (both use Qt 5.7.0) on my work PC the FFT visualization was garbage. Snooping into my code I found that the sample type provided by QAudioBuffer from QAudioProbe was Signed (in my work PC) while it was float in my Laptop. Here is the code that is called whenever QAudioProbe emits that data has been buffered:
void SpectrumController::setAudioBuffer(QAudioBuffer buffer){
// Used to momentarily stop the process.
if (!enableBuffering) return;
// Only process stereo frames
if (buffer.format().channelCount() != 2) return;
if (buffer.format().sampleType() == QAudioFormat::SignedInt){
//qWarning() << "Signed";
QAudioBuffer::S16S *data = buffer.data<QAudioBuffer::S16S>();
bufferData(data,buffer.frameCount());
}
else if (buffer.format().sampleType() == QAudioFormat::UnSignedInt){
//qWarning() << "Unsigned";
QAudioBuffer::S16U *data = buffer.data<QAudioBuffer::S16U>();
bufferData(data,buffer.frameCount());
}
else if(buffer.format().sampleType() == QAudioFormat::Float){
//qWarning() << "Float";
QAudioBuffer::S32F *data = buffer.data<QAudioBuffer::S32F>();
bufferData(data,buffer.frameCount());
}
}
template<typename T>
void SpectrumController::bufferData(T *data, qint32 N){
for (qint32 i = 0; i < N; i++){
//if (qAbs(data[i].left) > largest){largest = qAbs(data[i].left); qDebug() << "Largest" << largest;}
//currentBuffer << ((qreal)data[i].left/(largest));
//qWarning() << "Added data" << currentBuffer.last();
currentBuffer << data[i].left;
if (datcounter < 100000){
*writer << data[i].left;
*writer << "\n";
datcounter++;
}
else if (writeFile->isOpen()){
qWarning() << "Closed file";
writeFile->close();
}
if (currentBuffer.size() == FFT_SIZE){
dataBuffer << currentBuffer;
currentBuffer.clear();
if (!isRunning) run();
}
What I ended up doing is writing, to a file, the first 100.000 points of data gathered by both my laptop and my work PC in order to plot them.
This is what I've got
What I think is that difference is in the base system's handling of the the mp3, which, in turn, is what Qt uses. I think is gstreamer. Centos uses a much older version. The plot on the right corresponds to my laptop while the plot on the left corresponds to my work pc.
Any ideas on how to fix this? Or am I just stuck with no way of accessising the raw audio data correctly?
UPDATE:
Even though this is not a Fix or anything like that, the data in the other channel (data[i].right) did have more appropiate data. I'm using the right channnel, for now.
I have a such problem:
I develop a simple database (PostgreSql).
One of the features that it keeps in column (column name: "ascii") a big text data (2000 rows) that reads from file (datatype in the table is BYTEA).
Here is the example of the code where I insert the data:
QFile *asciiFile = new QFile(ui->ascii_lineEdit->text());
asciiFile->open(QIODevice::ReadOnly);
QByteArray asciiArray = asciiFile->readAll();
qDebug() << asciiArray;
QSqlQuery *sourceQuery = new QSqlQuery();
sourceQuery->prepare("INSERT INTO source (image, image_material, archive, ascii, about) VALUES (:image, :image_material, :archive, :ascii, :about)");
sourceQuery->bindValue(":image", graphArray.toBase64());
sourceQuery->bindValue(":image_material", materialArray.toBase64());
sourceQuery->bindValue(":archive", archiveArray.toBase64());
sourceQuery->bindValue(":ascii", asciiArray.toBase64());
sourceQuery->bindValue(":about", ui->about_textEdit->toPlainText());
sourceQuery->exec();
Once more, the datatype of the column("ascii") that keeps is BYTEA.
Now I try to read this data (near 2000 lines) and they not displayed as well.
I try this method:
QByteArray asciiArray = QSqlQuery query = connector->getSourceAscii(item_id);
query.next();
QByteArray asciiArray = QByteArray::fromBase64(query.value("ascii").toByteArray());
QString *result = new QString(asciiArray);
qDebug() << *result;
It must be a lines of the digits but I have something like this:
�w߇�k��ۇ������z���������燸��wӇ�k�{�����w��};��{��x{��k�{k�{k�xk�x߾���{k�{�����������wㇸ��
The examples of the lines that I need:
2490 0,21979421377182 4,82690520584583E-02
2491 0,226718083024025 4,33071963489056E-02
Have you any suggestion about this? Thanks.
In my Qt app I want to read exif data of images. QImage or QPixmap don't seem to provide such hooks.
Is there any API in Qt that allows reading exif without using external libraries like libexif?
EDIT: This is a duplicate of this
For me, the best choice was easyexif by Mayank Lahiri. You only need to add two files exif.cpp and exif.h to your project.
int main(int argc, char *argv[])
{
for (int i=1; i<argc; ++i){
QFile file(argv[i]);
if (file.open(QIODevice::ReadOnly)){
QByteArray data = file.readAll();
easyexif::EXIFInfo info;
if (int code = info.parseFrom((unsigned char *)data.data(), data.size())){
qDebug() << "Error parsing EXIF: code " << code;
continue;
}
qDebug() << "Camera model : " << info.Model.c_str();
qDebug() << "Original date/time : " << info.DateTimeOriginal.c_str();
} else
qDebug() << "Can't open file:" << argv[i];
}
return 0;
}
Try QExifImageHeader from qt extended framework. qtextended.org is not available for me? but you may search for other download mirrows.
QImageReader has a method named transformation() which is introduced in version 5.5, first you should try that.
You can also check the following link to see how it's done using Windows GDI in Qt, http://amin-ahmadi.com/2015/12/17/how-to-read-image-orientation-in-qt-using-stored-exif/