Can't convert QString to LPCWSTR
Hello guys, i have this code:
Code:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "urlmon.h"
#include "string"
#include "iostream"
#include "cstring"
//...A lot of s*it!
void MainWindow::on_pushButton_clicked()
{
path = ui->lineEdit_2->text();
url= ui->lineEdit->text();
ui->label_2->setText(url+"//"+path);
URLDownloadToFile(NULL,&url,&path,NULL);
}
//other sh*t
I've got an error in the line
Code:
URLDownloadToFile(NULL,&url,&path,NULL);
...\mainwindow.cpp:27: error: cannot convert 'QString*' to 'LPCWSTR {aka const wchar_t*}' for argument '2' to 'HRESULT URLDownloadToFileW(LPUNKNOWN, LPCWSTR, LPCWSTR, DWORD, LPBINDSTATUSCALLBACK)'
URLDownloadToFile(NULL,&url,&path,NULL);
Re: Can't convert QString to LPCWSTR
That's because a pointer to a QString ("&url") is not a wchar_t pointer. Use one of these as the argument:
Code:
url.toStdWString().c_str()
// or
url.utf16()
You will probably run into trouble later in your coding life if you continue to write code that #includes system files with the "" convention instead of the <> convention:
Code:
// Should be
#include <cstring>
// and not
#include "cstring"
This is because the "" convention tells the compiler to look first in the current directory (and in directories you explicitly tell the compiler to look in) for the include file, then look in system directories. The <> convention tells the compiler to look only in system directories. If one of those other directories accidentally contains a file with the same name as the system file, then you'll likely end up with all sorts of unexplained compilation errors that will take a while to figure out. If you mean to include a system file, then help the compiler out by telling it that.