Symbol does not show up on ArcGIS Map using Qt - c++

I am using Qt together with the ArcGIS api and I want to display a military symbol using the MessageHelper class. Here is my code:
m_map = new EsriRuntimeQt::Map(this);
m_mapGraphicsView = EsriRuntimeQt::MapGraphicsView::create(m_map, this);
setCentralWidget(m_mapGraphicsView);
m_map->setWrapAroundEnabled(false);
QString path = EsriRuntimeQt::ArcGISRuntime::installDirectory();
path.append("/sdk/samples/data");
QDir dataDir(path); // using QDir to convert to correct file separator
QString pathSampleData = dataDir.path() + QDir::separator();
// ArcGIS Online Tiled Basemap Layer
m_tiledServiceLayer = new EsriRuntimeQt::ArcGISTiledMapServiceLayer("http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer", this);
m_map->addLayer(m_tiledServiceLayer);
// test message processing
m_msgGroupLayer = new EsriRuntimeQt::MessageGroupLayer(EsriRuntimeQt::SymbolDictionaryType::Mil2525C);
m_map->addLayer(m_msgGroupLayer);
// build message
EsriRuntimeQt::Point pt(0, 0, m_map->spatialReference());
QList<EsriRuntimeQt::Point> controlPoints;
controlPoints.push_back(pt);
EsriRuntimeQt::Message msg = EsriRuntimeQt::MessageHelper::createUpdateMessage(EsriRuntimeQt::SymbolDictionaryType::App6B, "1", "position_report", controlPoints);
// process the message
m_msgGroupLayer->messageProcessor()->processMessage(msg);
I only see the map but no symbol. I am using Qt-Creator 5.7 and the ArcGIS sdk 10.2.6. Am I somthing missing or is something wrong with my point definition? I expect the symbol to see in the middle of the world map as I use the default spatial reference but I don't see anything there.

The layer and the message use 2 different symbol dictionary types - the layer is created with Mil2525C and the message is created with App6B. These should match.

Related

Turning on android flashlight in Qt6

Currently I'm trying to make an mobile app and I need to turn on the flash light of a mobile device. Actually I want to use it as a torch(On/off/blink etc). I searched in the qt docs and found QCamera class. But I'm unable to turn the light on. I'm using Qt 6.3.1. Can anyone help?
I'm doing something like this:
// In constructor of a widget class,
cam = new QCamera(QCameraDevice::BackFace, this); //cam is declared in the header file
// In a function, called after a button click,
// cam->setFlashMode(QCamera::FlashOn);
cam->setTorchMode(QCamera::TorchOn);
cam->start();
I added this code inside a function and called it after a button-click event. But when I click the button, nothing happens.
UPD:
What I have found interesting is, I've tried printing the return value of isFlashModeSupported() and it returns false!
QString str = cam->isFlashModeSupported(QCamera::FlashOn) ? "Flash: Yes" : "Flash: No";
ui->Flash->setText(str); // str = "Flash: No"
I'm using a phone which has controllable flash light. So what can be the reason for this kind of behaviour?

Displaying picture that is not in resources of Qt

I am currently writing an application in Qt, which is basically a warehouse. An application reads CSV, enables user to process it and enables to show picture of each good. I tried displaying picture using QLabel and Pixmap, however nothing happens even though the file is in the same folder and the name provided is exactly as it should be. Is it the resources issue or my code fails somehow? Is there any possibility to display the image without adding it to resources in order to avoid adding many photos manually?
void ImageViewer::viewImage(QString imgName)
{
QString pathWithName = imgName;
pathWithName.append(".jpg");
ui->label->setPixmap( QPixmap(pathWithName) );
ui->label->show();
update();
}
Sorry for any mistakes in post creation or code displaying here- it's my first post.
Edit:
I am adding code from MainWindow (called CsvReader in my project) to how I'm invoking the method viewImage:
void CsvReader::on_imgView_clicked()
{
ImageViewer* img = new ImageViewer(this);
img->setModal(true);
img->exec();
QModelIndex List selInd ui->tableView->selectionModel()->selectedIndexes();
QString id = model->item(selInd.first().row(), 0)->text();
img->viewImage(id);
}
Edit 2:
Solved. Had to change path using QDir:
QDir* directory = new QDir("/home/kokos/Magazyn/photos");
QFileInfo checkFile(*directory, pathWithName);
Thanks in advance,
Kokos
Confirm your file's location and existence first. Add this;
QFileInfo checkFile(pathWithName);
if (checkFile.exists() && checkFile.isFile()) {
// your code
}

How to populate a TreeView made in resource script

I have to make a C++, VSPackage that contains a TreeView. I added one in the default dialog window of the project resource script (*.rc) from the toolbox window. The problem is that I don't know how to add items to it.
I looked on many websites but they have code for C# or other types of projects.
I found a project made by Song Ho Ahn and also the source code that can be found at the bottom of this website TreeView.
I tried to go to the TreeView properties window to see if there is something so I can add items to it and then finding a way to replace them, but nothing. I tried to use the code he written just to help me find a solution to my problem, but I couldn't find it. Maybe it's the "handler" and the "parent", which I don't know how to use.
void set(HWND parent, int id, bool visible=true)
{
this->parent = parent;
handle = GetDlgItem(parent, id);
if(!visible) disable();
}
I want to mention that I'm a beginner with VSPackage and that I didn't made a project this big before.
If somebody can explain to me what to do, send me on a path or even say that I'm stupid and the solution is a simple one, I will appreciate it very much.
In the snippet you've posted, you're using native WIN32 API. So you might look into the documentation of TVM_INSERTITEM message.
Here is a little snippet to add a single entry to a TreeView control (regardless if created by a resource script or a call of CreateWindow(..)):
TVITEM tvi;
TVINSERTSTRUCT tvins;
HTREEITEM hItem;
/* setup new item */
tvi.mask = TVIF_TEXT; // just text
tvi.pszText = "Hello TreeView!";
tvi.cchTextMax = 0; // ignored if creating the item
/* setup insertion structure of item */
tvins.hParent = TVI_ROOT; // insert item at root level
tvins.item = tvi; // item description setup above
tvins.hInsertAfter = NULL; // instert on top of the tree view
hItem = (HTREEITEM)SendMessage(GetDlgItem(hWnd, IDC_TREEVIEW), // update parameters of GetDlgItem(..) according to your code
TVM_INSERTITEM,
0,
(LPARAM)(LPTVINSERTSTRUCT)&tvins);
if (hItem == NULL)
{
/* something went wrong */
}

Using images in QListWidget, is this possible?

I am using QT to create a chat messenger client. To display the list of online users, I'm using a QListWidget, as created like this:
listWidget = new QListWidget(horizontalLayoutWidget);
listWidget->setObjectName("userList");
QSizePolicy sizePolicy1(QSizePolicy::Preferred, QSizePolicy::Expanding);
sizePolicy1.setHorizontalStretch(0);
sizePolicy1.setVerticalStretch(0);
sizePolicy1.setHeightForWidth(listWidget->sizePolicy().hasHeightForWidth());
listWidget->setSizePolicy(sizePolicy1);
listWidget->setMinimumSize(QSize(30, 0));
listWidget->setMaximumSize(QSize(150, 16777215));
listWidget->setBaseSize(QSize(100, 0));
listWidget->setContextMenuPolicy(Qt::CustomContextMenu);
Users are shown by constantly refreshing the list, like this: (Note: There are different channels, with different userlists, so refreshing it is the most efficient thing to do, as far as I know.)
void FMessenger::refreshUserlist()
{
if (currentPanel == 0)
return;
listWidget = this->findChild<QListWidget *>(QString("userList"));
listWidget->clear();
QList<FCharacter*> charList = currentPanel->charList();
QListWidgetItem* charitem = 0;
FCharacter* character;
foreach(character, charList)
{
charitem = new QListWidgetItem(character->name());
// charitem->setIcon(QIcon(":/Images/status.png"));
listWidget->addItem(charitem);
}
}
This has always worked perfectly. The line that I commented out is the one I have problems with: my current goal is to be able to display a user's online status with an image, which represents whether they are busy, away, available, etc. Using setIcon() does absolutely nothing though, apparently; the items still show up as they used to, without icons.
I'm aware that this is probably not the way this function needs to be used, but I have found little documentation about it online, and absolutely no useful examples of implementations. My question is, can anybody help me with fixing this problem?
This is how you may conduct your debugging:
Try the constructor that has both icon and text as arguments.
Try to use that icon in another context to ensure it is displayable (construct a QIcon with same argument and use it elsewhere, e.g. QLabel!).
Use icon() from the QListWidgetItem to receive back the icon and then look at that QIcon.
Create a new QListWidget, change nothing, and ordinarily add some stock items in your MainWidget's constructor. See if the icons show up there.

Generating word documents (.doc/.odt) through C++/Qt

I am using Qt 4.5.3 and Windows XP. I need my application to generate documents that contains the information that is being used and generated. The information that is being used will be just strings (QString to be more specific) and the information that is being generated will be strings and images as well.
I want documents to be a MS word document (.doc) or can be an Open Document Format (.odt) Also I want the documents to be formatted with fonts,images, tables of data, some background colors and all.
I have done the creation PDF files using QTextDocument, QTextCursor and QPrinter. But when I tried to apply the same QTextDocument for odt, I ended up with just format error.
Is there a way to generate such documents using any other libraries that use C++? How you guys use to generate such documents (.odt/.doc) in C++? Any pointers, links, examples regarding this are welcome.
I have done this through the Qt way. i.e by using ActiveQt module.
The reference documentation for MS Word can be obtained through,
MSDN documentation, which actually pointed to the VBAWD10.chm file that has the ActiveX apis for MS Word.
The Word Application can be initialized by
QAxWidget wordApplication("Word.Application");
The sub-objects of the word application can be obtained through the function,
QAxBase::querySubObject()
For e.g:
QAxObject *activeDocument = wordApplication.querySubObject("ActiveDocument");
To pass the obtained sub-object as an argument,
QVariant QAxBase::asVariant () const
Any function calls involving the word object can be called using the function using,
QAxBase::dynamicCall ()
For e.g:
activeDocument->dynamicCall("Close(void)");
After a quite good amount of struggle and few convinces, it's working fine. :)
Hope it helps for those who are all looking for similar solutions...
maybe you can use this and write to a file in odf format http://doc.trolltech.com/4.6/qtextdocumentwriter.html#supportedDocumentFormats qt does not know how to output doc docx etc but you can use com(activeQt) or some other library to write in those or other formats you need
For me, a better way of automating Office applications is importing the object model from the MS Word COM type library into the C++ project. This is very similar to the Qutlook Example for the Outlook application. You can extrapolate the technique to Excel and PowerPoint if you want, using oleview.exe to obtain the library Guids. Here is a complete project at GitHub.
The QMake project file :
QT += widgets axcontainer
CONFIG += c++11 cmdline
DEFINES += QT_DEPRECATED_WARNINGS
DUMPCPP=$$absolute_path("dumpcpp.exe", $$dirname(QMAKE_QMAKE))
TYPELIBS = $$system($$DUMPCPP -getfile {00020905-0000-0000-C000-000000000046})
isEmpty(TYPELIBS) {
message("Microsoft Word type library not found!")
REQUIRES += StackOverflow Rocks
} else {
SOURCES = main.cpp
}
The main.cpp source:
#include <QApplication>
#include <QStandardPaths>
#include <QDir>
#include "MSWORD.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Word::Application word;
if (!word.isNull()) {
word.SetVisible(false);
Word::Documents* docs = word.Documents();
Word::Document* newDoc = docs->Add();
Word::Paragraph* p = newDoc->Content()->Paragraphs()->Add();
p->Range()->SetText("Hello Word Document from Qt!");
p->Range()->InsertParagraphAfter();
p->Range()->SetText("That's it!");
QDir outDir(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation));
QVariant fileName = outDir.absoluteFilePath("wordaut.docx");
QVariant format = Word::wdFormatXMLDocument;
newDoc->SaveAs2(fileName, format);
QVariant fileName2 = outDir.absoluteFilePath("wordaut2.doc");
QVariant format2 = Word::wdFormatDocument;
newDoc->SaveAs2(fileName2, format2);
newDoc->Close();
word.Quit();
}
return 0;
}