QImageWriter not working - QML
-
I've been trying to use QImageWriter to add metadata to a tiff file but when I I run the code it gives me the error that QImageWriter is not defined. I have added the necessary code to the CMAKE and main.cpp header but it still seems to be giving me an error. This is being written in QML. Any help or guidance in an alternative way to write metadata to tiff would be greatly appreciated. Thanks!
-
I've been trying to use QImageWriter to add metadata to a tiff file but when I I run the code it gives me the error that QImageWriter is not defined. I have added the necessary code to the CMAKE and main.cpp header but it still seems to be giving me an error. This is being written in QML. Any help or guidance in an alternative way to write metadata to tiff would be greatly appreciated. Thanks!
@Dillon can you give more details of how you are trying to do this. Is it when you are trying to call something from QML that you are getting this error?
QImageWriterisn't directly accessible from QML so how are you exposing its functionality to the QML layer (if indeed that is what you are trying to do)? -
Ahhh, yes. That may be the issue then. I found an example (modified below)
var writer = new QImageWriter() writer.setFormat("tiff") writer.setText("Creator", "Dillon") writer.setText("Geog Ellipsoid", "GRS 1980") writer.write(image)I am not too familiar with how to use the functions from the C++ side of things.
Basically, I have an image that I am grabbing from the view and then I want to add metadata to the image before saving the file.
I have already setup the file dialog save function and that is working well but now I need to add the metadata prior to saving. -
Ahhh, yes. That may be the issue then. I found an example (modified below)
var writer = new QImageWriter() writer.setFormat("tiff") writer.setText("Creator", "Dillon") writer.setText("Geog Ellipsoid", "GRS 1980") writer.write(image)I am not too familiar with how to use the functions from the C++ side of things.
Basically, I have an image that I am grabbing from the view and then I want to add metadata to the image before saving the file.
I have already setup the file dialog save function and that is working well but now I need to add the metadata prior to saving.@Dillon exactly how to go about it will depend on your requirements. I'm on my phone so can't write code easily, but the docs explain the different methods available: https://doc.qt.io/qt-5/qtqml-cppintegration-overview.html
Edit: if all you need to do is to call that code you listed, as a function, I would probably use the approach documented here:
https://doc.qt.io/qt-5/qtqml-cppintegration-contextproperties.html
Look at the "Setting an Object as a Context Property" section. Basically, it involves creating a simple class that has your function as a method. You then register an instance of your class as a "context property".
-
@Bob64 Thank you for the direction. I tried utilizing that but I am getting an error during with CMAKE referencing something with the obj. I may be doing this completely wrong but I have not had any luck with it.
Also, Just from looking over some of that feature it seems as though I will only be able to write predefined text from the C++ class? The function will need to change the data depending on certain parameters.
Again, I may be completely off on understanding this. Thanks for your help so far!
-
@Bob64 Just an update, the error I am getting is stating that there is no file or directory for pthreads when I add the class to the main.cpp file. It will not compile. I have tried changing the compiler to MinGW and the pthread issue disappears but then I get an error command line '-' and the application will not load. I am at a loss as what to do next.