how to add raster image in Qt creator using ArcGisRuntime SDK - qt

This is the code i have written, but not able to display a raster image.
#include "Map.h"
#include "MapGraphicsView.h"
#include "Raster.h"
#include "RasterLayer.h"
using namespace Esri:: ArcGISRuntime;
Raster_example::Raster_example(QWidget* parent /*=nullptr*/):
QMainWindow(parent)
{
Raster* raster = new Raster("D:/Sony/blr.tif", this);
// Raster* raster = new Raster(buildRasterPath,this);
RasterLayer rasterLayer = new RasterLayer(raster);
// m_map.getOperationalLayers().add(rasterLayer);
// Create the Widget view
m_mapView = new MapGraphicsView(this);
following are the errors I'm getting when i run my code:
error: no viable conversion from 'Esri::ArcGISRuntime::RasterLayer *' to 'Esri::ArcGISRuntime::RasterLayer'
candidate constructor not viable: no known conversion from 'Esri::ArcGISRuntime::RasterLayer *' to 'const
Esri::ArcGISRuntime::RasterLayer &' for 1st argument; dereference the
argument with *
C:\Qt\Qt5.13.0\5.13.0\msvc2017_64\include\QtCore\qglobal.h:372: expanded from macro 'Q_DISABLE_COPY'
error: C2440: 'initializing': cannot convert from 'Esri::ArcGISRuntime::RasterLayer *' to
'Esri::ArcGISRuntime::RasterLayer'
No constructor could take the source type, or constructor overload resolution was ambiguous

new SomeClass(...) creates an instance of someClass and returns a pointer to that class. So it should be like
RasterLayer *rasterLayer = new RasterLayer(raster);

Related

shared_ptr not changing object (Visual studio 2012)

I have a really strange problem. I can't modify the object I am pointing to with a shared_ptr.
Example code:
#include<memory>
#include<iostream>
using namespace std;
class foo
{
public:
int asd;
foo(){}
~foo(){}
};
void d(shared_ptr<foo> c)
{
c->asd = 3;
}
void main()
{
foo a;
a.asd = 5;
d(make_shared<foo>(a));
cout<<a.asd; //asd is still 5
}
As far as I know you can access the object pointed to by the shared_ptr by using the "->" operator, so what am I doing wrong here? How can I change the asd variable inside the class via the shared pointer?
// create a temporary object by copying a
// the shared pointer you pass to d function actually points to this temporary object
d(make_shared<foo>(a));
// allocate and store foo object in shared_ptr instead
auto p_a(make_shared<foo>());
p_a->asd = 3;
d(p_a);
... so what am I doing wrong here?
From cppreference on std::make_shared [emphasis mine]:
template< class T, class... Args >
shared_ptr<T> make_shared( Args&&... args );
Constructs an object of type T and wraps it in a std::shared_ptr
using args as the parameter list for the constructor of T.
In your case, you supply an instance of foo as argument to std::make_shared, which will be used when constructing a new object of type foo; i.e., making use of the default supplied copy CTOR of foo (foo(const foo&)). This new object will be a temporary and only live for the call to d(...).

how to append element to a QList in a structure?

I have a struct like this one :
struct Nom {
QString Nom;
....
QList<quint64> indNum;
}
In my .h file. I declare :
QVector *n;
In my .cpp file. I declare :
n = new QVector<Nom>;
I read a file to fill in n.
When I write this :
n->back().indNum.append(i->size()-1);
it works.
When I write that :
n->at(j).indNum.append(i->size()-1);
I have a compilation error:
no matching member funtion for call to 'append'
candidate function not viable: 'this' argument has type 'const
QList', but method is not marked
const void append(const T &t);
I don't understand why it works in the first case and the second.
Could anyone explain and help me solve this ?
Thanks in advance.
QVector::at returns a const reference to the Nom value, so you cannot modify the item returned by n->at(j). To get a non-const reference you can use (*n)[j].
n->back() works because for QVector::back there is a const and a non-const overload.

How to use QSet as value in QMap?

I'm using Qt and I want to declare following container:
QMap<QUrl , QSet<ClassSharedPtr> > map;
Here ClassSharedPtr is the boost shared ptr of class "Class".
typedef boost::shared_ptr<const Class> ClassPtr;
I'm getting following errors after adding header file #include :
error: no matching function for call to ‘qHash(const boost::shared_ptr<const Class>&)’
QSet's value data type must be an assignable data type. In addition, the type must provide operator==(), and there must also be a qHash() function in the type's namespace that returns a hash value for an argument of the values's type.
So, you should implement qHash() function for boost::shared_ptr<const Class>.
namespace boost {
uint qHash(const boost::shared_ptr<const Class> &key, uint seed = 0)
{
const Class *ptr = key.get();
return uint(ptr) ^ seed;
}
}

C++/CLI How to translate this code ?

I dont know a lot about C++, but I have to make work some C++ code with .NET. I try with DLLImport but I failed. So I try with C++/CLI to make kind of a wrapper.
But I'm not sure to understand everything...
This is the basic C++ H file with the function I want to export (MyFunction)
extern "C"
{
__declspec(dllexport) IplImage* MyFunction(IplImage *src, std::string* name, OneEnumerationType myEnum, bool myBool, float myFloat);
}
This is the Wrapper h code.
#include "MyFunction.h"; // the file containing the h code
#include <string>
namespace MyWrapper{
public ref class MyWrapperClass {
public:
MyWrapper(){};
IplImage^ GetMyFunction(IplImage *src, std::string^ name, OneEnumerationType myEnum, bool myBool, float myFloat);
}
This is the Wrapper cpp code.
#include "MyWrapperCode.h";
namespace MyWrapper{
IplImage^ MyWrapperClass::GetMyFunction(IplImage* src, std:string^ name, OneEnumerationType myEnum, bool myBool, float myFloat){
MyFunction(src, name, myEnum, myBool, myFloat);
}
}
These are my questions :
1) When I'm compiling, the error is "'^ : cannot use this indirection on type IplImage' and same message for type "std::string".
I have followed this logical :
ClasseNative clNat2 = *clNat; --> ClasseManagee clMan2 = *clMan;
ClasseNative &clNat3 = clNat2; --> ClasseManagee %clMan3 = clMan2;
ClasseNative *clNat4 = &clNat2; --> ClasseManagee ^clMan4 = %clMan2;
I have seen, that It was better to use System::String. I try this way but the initial function is using std::string... BTW, why is it better to change ?
2) How do I get the MyFunction IplImage result ? Thru a private member and a get I suppose but I dont know how to initialize it...
3) Tricky question. Is it possible for me to put the CLI obtains IplImage structure (from the OpenCV library) (the result of my function) inside a IplImage .NET structure, when I ll called my wrapper ? Dont know if the question is understandable...
Thanks a lot for your help.
Turning around for 3 days on this problem...
Your wrapper class needs to create a new std::string based on the content of a System::String^ parameter then pass to your native function. Otherwise you need to rewrite the function to take something else as the string input, for example a LPWSTR or LPCSTR.
You can write a ref class to have properties for all data that an IplImage would have, then pass that to your wrapper class. Your wrapper class then create an IplImage object based on the data of the ref class and pass to the native function. Reverse the data copying direction for the return value.
1) just by adding ^ you cannot change a native object to become managed, you have to create wrappers or transfer the data for example:
std::string nativeString = "my string";
String^ managedString = gcnew String(nativeString.c_str());
//now you can return it as
2) create a managed wrapper or use primitive datatype to transfer the data
3) note sure if this will help but look at Emgu.CV
try reading abit more about C++\CLI here are a few nice tutorials:
Quick C++/CLI - Learn C++/CLI in less than 10 minutes
C++/CLI for the C# programmer

force call to QString(const char *) constructor in Qt 4.7

I am trying to compile a library written in Qt 4.6. On my current Linux machine I have only Qt 4.7 installed. The following code part:
/*file try.h*/
void fileOpen(QString s = NULL) ;
/*file try.cpp*/
void MainWindow::fileOpen(QString s) {
QString filename ;
if(s.isNull()) filename = QFileDialog::getOpenFileName(
this,
"Choose a file",
".",
"Source file (*.)");
else filename = s ;
}
compiles with the following error (I used cmake but the corresponding line code is the one listed above):
In member function ‘virtual int MainWindow::qt_metacall(QMetaObject::Call, int,
void**)’:
/homes/combi/hodorog/Developments/axelOld/build/axel/src/QGui/moc_MainWindow.cxx:141:26:
error: conversion from ‘long int’ to ‘QString’ is ambiguous
/homes/combi/hodorog/Developments/axelOld/build/axel/src/QGui/moc_MainWindow.cxx:141:26:
note: candidates are:
/usr/include/QtCore/qstring.h:426:43: note: QString::QString(const char*)
/usr/include/QtCore/qstring.h:105:14: note: QString::QString(const QChar*)
So I am guessing the problem is that in qt. 4.7. there are two QString constructors that can take a pointer as an argument (as listed in the compilation error), whereas in qt 4.6. there is only one QString constructor that can take a pointer as an argument. How can I force QString to call the constructor with const char * as an argument?
Thank a lot for your help in advance,
madalina
void fileOpen(QString s = NULL);
You are trying to construct a QString object with 0. It seems you are confusing the null of pointers with a null QString. A null QString is one which is created with the constructor QString(). Given how your function is implemented (referring to s.isNull()), you should change the function declaration to
void fileOpen(QString s = QString());

Resources