Getting error C2664 when trying to use WinRT C++/CX in a Qt 5.6 app on Platform::String
-
It was kind of a pain getting the C++/CX stuff working in QtCreator, but I finally got it to compile up to this point. I get this same error in Visual Studio 2015.
The original project had other stuff in it and was from Visual Studio 2013 and Qt 5.5. I moved the project to VS 2015 and got the same error. I then recreated just the problem part from scratch to figure out any possible configuration issues. This is what I currently have running in QtCreator 3.6.1 using Qt 5.6.0.
I'm used to C# and am new to Visual Studio and Qt so I'm guessing this is something obvious I'm missing but I can't find anything useful (to me) about this error.
The specific error is --
error: C2664: 'long __winRT::__getActivationFactoryByPCWSTR(void *,Platform::Guid &,void **)': cannot convert argument 1 from 'const wchar_t [44]' to 'void *'
The same error happens on the lines
String^ deviceSelector = WiFiDirectDevice::GetDeviceSelector();
and
create_task(DeviceInformation::FindAllAsync(deviceSelector)).then([this](task<DeviceInformationCollection ^> resultTask)
I created a new Qt widget project with a QMainWindow. The main.cpp was not changed. Here is my MainWindow code.
MainWindow.h
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include "appsettings.h" #include "ppltasks.h" class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); QString QStringFromString(std::wstring in); void getDevices(); }; #endif // MAINWINDOW_H
MainWindow.cpp
#include "mainwindow.h" #include <QtWidgets> #include <roapi.h> #include <vccorlib.h> using namespace Platform; using namespace Windows::Devices::Enumeration; using namespace Windows::Devices::WiFiDirect; using namespace concurrency; MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { RoInitialize(RO_INIT_MULTITHREADED); // WRT stuff initialization getDevices(); } MainWindow::~MainWindow() { RoUninitialize(); } void MainWindow::getDevices() { qDebug() << "getDevices"; // Find all discoverable peers with compatible roles // Get the device selector for querying WiFiDirect devices String^ deviceSelector = WiFiDirectDevice::GetDeviceSelector(); create_task(DeviceInformation::FindAllAsync(deviceSelector)).then([this](task<DeviceInformationCollection ^> resultTask) { try { DeviceInformationCollection^ devInfoCollection = resultTask.get(); if (devInfoCollection && devInfoCollection->Size > 0) { for (unsigned int i = 0; i < devInfoCollection->Size; i++) { String^ Name = devInfoCollection->GetAt(i)->Name; std::wstring ws(Name->Begin()); qDebug() << "Device:: " << QStringFromString(ws); } } else { qDebug() << "No devices..."; } } catch (Exception^ e) { String^ eMsg = e->Message; std::wstring ews(eMsg->Begin()); qDebug() << "ERROR:: " << QStringFromString(ews); } }); } QString MainWindow::QStringFromString(std::wstring in) { std::string str(in.begin(), in.end()); return QString(str.c_str()); }
-
@Simurr
Hello,
The compiler error is pretty self explanatory:
The first parameter is expected to bevoid *
(or any other mutable pointer because of implicit conversion), but you're passing alongconst wchar_t [44]
(which is equivalent toconst wchar_t * const
, which is const). So the compiler can't convert from one type to the other. Find the exact line the function is called and fix the types.Also, this couldn't possibly be standard C++, what's with the circumflex (
^
)?
^
is the bitwise XOR and I don't see how, or rather why, it got in so many places ...Kind regards.
-
@kshegunov it is not self explanatory to me because WiFiDirectDevice::GetDeviceSelector() returns a "String^" so what conversion is there?
The WiFi Direct API is part of WinRT. That is where "^" comes from. It's the WinRT (C++/CX?) equivalent of "*", or so I understand.
-
This seems to be a problem with a Qt Desktop app trying to use the WinRT libraries using C++/CX. I am getting the same error for every WinRT API call (WiFi Direct stuff) I've tried so far.
Can Qt 5.6 use C++/CX to use parts of the WinRT API? Either this isn't going to work or I'm missing something that I would think would be documented somewhere.