Remove Warning- QML Connections: Cannot assign to non-existent property "onValueChanged" - qt

My code runs fine as expected but why do I get the warning messsage:
QML Connections: Cannot assign to non-existent property "onValueChanged"
Here is how I linking to signal.
Connections {
target: myModel
onValueChanged: {
console.log("Valued changedRecieved in QML")
}
myModel is a C++ class that I am exposing to QML using engine.rootContext()->setContextProperty("myModel", &model);
Is there a way to remove this warning?

In your Connections scope just set ignoreUnknownSignals: true

Related

Create component dynmically in QML (ListElement in ListModel)

I want to create members of an QML-ListModel dynamically. Static creation is no problem and works fine:
ListModel{
id: sList
ListElement{
url: "Res/ex1.jpg"
time: 10
}
ListElement{
url: "Res/ex2.jpg"
time: 10
}
}
I chosse QML function Qt.createQmlObject, sList was already create at startup:
Qt.createQmlObject("import QtQuick 2.5; ListElement{url: \"Res/ex1.jpg\"; time: 10; }", sList, "dynamicItem");
I finally got an error:
file:///C:[...]TEP46Py6_2/main.qml:156: Error: Qt.createQmlObject(): failed to create object:
file:///C:[...]TEP46Py6_2/dynamicItem:1:53: Cannot assign to non-existent property "time"
Yes, ListElement hasn't a native property time (and also url), but ListElement commonly has no native properties. Could anybody give me an advice? Thank you.
You just have to use the append function:
sList.append({"url": "Res/ex1.jpg", "time": 10})

QML Connections: Implicitly defined onFoo properties in Connections are deprecated

I got the following error message when upgraded to Qt 5.15:
QML Connections: Implicitly defined onFoo properties in Connections are deprecated.
Use this syntax instead: function onFoo(<arguments>) { ... }
The corresponding QML code is pasted below
Connections {
target: AppProxy
onLogsReady: function(logs) {
textLogs.text = logs
}
}
where the onLogsReady is a signal defined in the AppProxy class:
class AppProxy : public QObject {
Q_OBJECT
Q_DISABLE_COPY(AppProxy)
public:
AppProxy(QObject* parent = 0);
~AppProxy();
signals:
void logsReady(QString logs);
// ...
};
I wonder how to suppress this warning.
in Qml 5.15 there is a new syntax for connections. In your case it would look like this:
Connections {
target: AppProxy
function onLogsReady(logs) {
textLogs.text = logs
}
}
You can read more about it here: https://doc.qt.io/qt-5/qml-qtqml-connections.html
In addtion to #luffy and #Lidekys solution in my case adding this line to pro file of the project is solved issue.
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
#luffy answer is correct, but not completely. If you'll just make these changes, at least for me, it didn't fix the issue. What fixed it was adding "import QtQml 2.15" (like stated in https://doc.qt.io/qt-5/qml-qtqml-connections.html) in the qml files that were affected by these changes.
Not sure if this helps, just wanted to add in to the issue.

Monolog handler ignoring yaml level

In Symfony 4.3 using Monolog, I have created a custom handler to push logs to AWS Firehose. Here is the constructor:
class FirehoseLogHandler extends AbstractProcessingHandler {
public function __construct(
FirehoseClient $firehoseClient,
FormatterInterface $formatter,
$streamName,
$level = Logger::INFO,
$bubble = true
) {
$this->firehoseClient = $firehoseClient;
$this->streamName = $streamName;
$this->formatter = $formatter;
parent::__construct($level, $bubble);
}
And here is my monolog.yaml config:
monolog:
handlers:
firehose_handler:
type: service
id: kinesis_stream_handler
main:
type: stream
handler: firehose_handler
level: error
channels: ["!event"]
services:
kinesis_stream_handler:
class: App\Logger\Handler\FirehoseLogHandler
arguments:
$firehoseClient: '#aws.firehose'
$formatter: '#App\Logger\Formatter\FirehoseLogFormatter'
$streamName: 'firehose-stream-test'
The problem that I am having is that the $level is always set to Logger::INFO (200), or whatever is set in the constructor. It seems to be ignoring what is set in the yaml config.
What am I doing wrong here? I know I could always add $level: 400 to the service declaration but that doesn't seem to make much sense. Appreciate any help in advance.
Handlers defined as type: service are used strictly as-is, since they are instances you have already constructed. They are not passed any arguments from the main monolog configuration; that would only apply to services it is constructing for you. So you do need to add $level as an explicit argument to your custom handler for this reason.
There may be some further confusion stemming from your main handler definition. While handler is a valid configuration key, it does not apply to a stream handler as it only makes sense for handlers that wrap others, such as filter. So that is simply being ignored.
The full list of handler types and what configuration keys actually apply to each can be found in the code here.

Drag file from application to explorer. Can my application do the copying?

In Qml I can start a drag using the text/uri-list mime type in order to start a copy action from my application into a file explorer, e.g.
Item {
id: draggable
anchors.fill: parent
Drag.active: mouseArea.drag.active
Drag.hotSpot.x: 0
Drag.hotSpot.y: 0
Drag.mimeData: { "text/uri-list": "file:///home/myname/Desktop/avatar.jpeg" }
Drag.supportedActions: Qt.CopyAction
Drag.dragType: Drag.Automatic
Drag.onDragStarted: { }
Drag.onDragFinished: {
console.log("Time to copy")
}
} // Item
or
Item {
id: draggable
anchors.fill: parent
Drag.active: mouseArea.drag.active
Drag.hotSpot.x: 0
Drag.hotSpot.y: 0
Drag.mimeData: { "text/uri-list": "https://farm1.staticflickr.com/713/21777111068_e3310cfb94_k.jpg" }
Drag.supportedActions: Qt.CopyAction
Drag.dragType: Drag.Automatic
Drag.onDragStarted: { }
Drag.onDragFinished: {
console.log("Time to copy")
}
} // Item
(see also Qt Quick Examples - externaldraganddrop)
This works fine given file: and http: URIs.
However my real data is not available as an URI but stored in a database. I cannot quickly store to temp because that can take seconds and user does not want a delay in the moment he starts a drag.
Is it somehow possible to get the target URI after the drop and do the copying myself? Or can only the target do the copying?
In the later case, do I need to make my data available via an internal HTTP-Server? How do I even know which URI scheme is supported by the file browsers on Linux, Windows and OS X?
I would use something like:
Drag.mimeData: { "text/uri-list": "http://localhost:8080/datarepository?id=12345" }
and then I'll make available the requested data on an in-application HTTP server (that then can easily extract the object having ID equal to 12345 in my example from DB)... (once the copy operation has started I don't think that it is a shame if your user waits some seconds while the system extracts the object from the DB).

How to bind to root context object signal from QML

I'm creating QML application (QT 5.2)
Assume I have some object set as root context:
viewer.rootContext()->setContextObject(&view_model);
Now I want to bind to a signal of view_model from QML:
Connections {
target: ??? WHAT SHOULD GO HERE ???
onSignalStateChanged: console.log("signal")
}
Cannot figure out what should be the target.
Important: I don't want to use setContextProperty.
It seems you can't use Connections if you don't have access to object instance (via context property for example). But you still could use following:
function onSignal() {
console.log( "signal" );
}
Component.onCompleted: {
onSignalStateChanged.connect( onSignal );
}

Resources