How to handle "bytes" in QML? - qt

Considering :
http://doc.qt.io/qt-4.8/qdeclarativebasictypes.html
there is no strict equivalent of "byte" in QML.
Nonetheless, I have to manipulate some datas in a whole project, and QML file are an intermediate for communications. And some of these datas are some byte...
What can I do ?
(found some links about QVariant but I don't feel like I can use it in QML)

I've already seen your question in Qt forum, but left with the intention that someone with better knowledge can help you.
Could you please tell about your necessity to use a byte in QML. If it is going to be standalone application, you can handle (and only can - I think) it using a C++ datatype like char and display/present it from the QML side.
If it just going to be a QML file, then I think you have to create a byte like object with Qt C++ and use it to store the values.
I definitely don't think that QML can handle file operations, neither can it access any serial port services. So the C++ can handle these situations without any difficulties.

If you don't actually use those bits in QML you might be able to save in an integer and then get those back.

Related

Change and update geometry mesh at runtime

This question and answer, in Oct 2015, implies it is possible to change Qt3D mesh and update it:
Question
I want to use Qt3d in a situation that involves dynamic runtime
changes of geometric data on the application side.
What is the best way to dynamically change a mesh for an entity?
I'd rather do all this on the C++ side, but QMesh doesn't seem to
provide an API for changing the mesh data.
I looked at some other examples of making a custom QAbstractMesh class
and QAbstractMeshFunctor. It looks like I could possibly make a custom
mesh type to do what I need but I have a question. If I keep a
reference to the QMeshDataPtr that I make from the functor, can I
simply modify the mesh data whenever I want and the entities that
reference it will update automatically?
Answer
The API for this has changed a little in 5.6. The geometric data is
now contained in one or more QBuffer objects and is referenced by one
or more QAttributes that describe the data layout in the buffers. The
QAttributes are rendered by adding them to a QGeometryRenderer
component.
You can either update the above objects on the main thread and call
update() or as before you can also use a functor to have the backend
generate the dynamic data.
Now, my question is about calling update(). Exactly what section of Qt3D API is referred to?
There is a test available at Qt installation directory on my Linux machine:
/home/{user}/Qt5.12.6/5.12.6/Src/qt3d/tests/manual/custom-mesh-update-data-cpp/
which I discovered by following this link when searching Google for qt3d mesh update keywords.
The above test is using Qt3DRender::QBuffer API to update mesh data:
void QBuffer::updateData(int offset, const QByteArray &bytes)
Updates the data by replacing it with bytes at offset.
Note: This function can be invoked via the meta-object system and from QML. See Q_INVOKABLE.
Code looks like this:
Qt3DRender::QBuffer *vertexDataBuffer;
// ...
QByteArray updateData;
// ...
vertexDataBuffer->updateData(pos,updateData);
// ...

How to Interact with a Qt C++ library inside a QML/QtQuick application?

I recently wrote a Qt based library to manage requests to TheMovieDB.org for a professional desktop application.
Not really experienced with QML and QtQuick, I think about migrating this application to QML which seems to be really adapted for.
I began few tutorials with QML...Amazing.
And now, I wonder if I can integrage my wrapper library into a QML application ?
Basically, let the user capture a movie name into a nice QML interface, froward the input parameters to the c++ wrapper, and retrieve the resulting json results + QPixmap object.
Is it something possible ? I found some piece of codes to access QML components from a Qt c++ application but the inverse yet.
Or maybe am I thinking the things the wrong way ?
Have you ever wrote something similar, I mean regarding the interaction mechanism?

Generating a waveform from an audio (or video) file?

I'm trying to understand how I can generate a waveform from an audio (or video) file to display to the user.
I've been googling around for quite a while now and can't determine if this is even possible in Qt without using something like FFmpeg. I've seen all of these classes: QMediaPlayer, QMediaContent, QMediaResource, QAudioProbe and experimented with the Qt Media Player Example but am just not seeing where I can access the actual audio buffer.
So I have 2 questions:
Is what I want to do even possible without 3rd party libraries?
If it is possible, can some kind soul outline what I need to read and understand in order to access the audio data
I have tried the suggestions from this question (Audio visualization with QMediaPlayer) but the result of audioProbe->setSource(player) is always false and the method processBuffer never gets called.
audioProbe = new QAudioProbe(this);
bool success = audioProbe->setSource(player);
qDebug() << success;
connect(audioProbe, SIGNAL(audioBufferProbed(QAudioBuffer)), this, SLOT(processBuffer(QAudioBuffer)));
Update: Adding some additional detail in the hope of clarifying things.
For testing/learning I am using the Media Player Example which ships with Qt, so it is set up correctly with Q_OBJECT etc.
For audio, I tested with both .mp3 and .wav files. FWIW, the player example won't play video for some reason (.mp4, .avi were tested)
The player in the code is QMediaPlayer – which inherits from QMediaObject. The example code for the Player class is here. I added my code (in original comment above) right after the player is instantiated. I also tried adding it once media is loaded.
I tried declaring my slot first as private, then as public – either way, it is never called.
Frustrating that such a simple thing is so hard.
Going the "no external library" route will likely just lead to more of a headache and more work than is necessary. The other advantage of going with an established library is you won't be bound to one file format, as not all formats store their data the same way. If the audio format is uncompressed (wav or other) you can read the header until you get to the data chunk. An answer to this question here details this in C. You should be able to get an idea for the file format from this to apply it to another language.
You will want to understand how many channels are in the wav file, bit depth, and also the sampling rate before you can do anything worthwhile with the data. All this info can be grabbed from the header.
It turns out that QAudioProbe is not supported on OSX – the platform I am working on. Took quite a while (a "Qt while. . .") to ferret that info out so I am posting it here explicitly.
See this document for full details: Qt 5.5.0 Multimedia Backends

Undocumented ProcessEventsFlag enums in QT

I noticed that modal dialogs on QT uses a local QEventLoop with the ProcessEventFlags set as "DialogExec"
eventLoop.exec(QEventLoop::DialogExec);
The QT assistant has no information on what this enum means. There is another one called EventLoopExec. Anyone has any idea what they actually mean and why aren't they documented?
Thanks
I did some poking around and this is what I found:
This enum is intentionally omitted from the documentation, along with several other QEventLoop::ProcessEventsFlag enum values (X11ExcludeTimers, ExcludeUserInput, WaitForMore, EventLoopExec) as there is an \omitvalue in front of each one in the comments that generate the docs.
There is only one place in all of Qt that actually uses it, in qeventdispatcher_mac.mm in which it appears to be some kind of mac-specific optimization according to the in-line comments
The intentional omission of these values from the docs leads me to conclude that they're for internal Qt use only, and that you shouldn't need to use them or worry about them.

generating GUI for C++ code

i need to generate a GUI for a ready code written with C++ the code is divided into some classes containing one that represent user interface to facilitate generating GUI without big modifications on my code
and i already designed the GUI window using QT Designer
now i want to link both logical part (my classes)and GUI part(QT Designer output class) ,how to add all classes to the GUI,how to handle signals coming from GUI and send the appropriate input to the logical part
GUI
get some words from user
get slider input as an int
add files from HDD (logical part need full paths)
out some text
NOTE:first time with QT
thanks in advance for any help
You might want to start with these simple tutorials
http://www.qttutorial.com/qt/hello-qt-your-first-application/
http://www.qttutorial.com/qt/hello-qt-your-first-qt-application-part-2/
I you need a really simple solution - call this in desired order:
QInputDialog::getText();
QInputDialog::getInt();
QFileDialog::getOpenFileName();
QMessageBox::information();
QtAssistant should give you much more details and examples.

Resources