Unsolved [HELP] C++ VS to QT
-
Hello / good evening,
I call on to you because I do not manage to realize what I would want to make.
I would like to convert this code written with Visual Studio on Qt.
Here is the code:
@
Wstring Username;
Wcin > > Username;
Username = L"Hello" + Username
@Current code:
@
std::wstring Username;
QString user = ui->lineEdit->text();
Username = L"Hello" + user;
@I want put my username in LineEdit.
Thank you if you can help me!
Best Regards,
John -
Hi and welcome to devnet,
First thing you should do is to use QString. That will simplify thing.
Is it a different QLineEdit ? What should trigger the update of that QLineEdit ?
The basic would to:
ui->otherLineEdit->setText(QStringLiteral("Hello") + ui->lineEdit->text());
-
Hello,
Thanks to you to have answered so fast!
I think that I badly expressed myself.
I am developing a software for the modification of a game.
I make the attachment for the process by detection of the name of the window.
The name of the window is: Call of Duty ® - ship - USERNAME (your steam username).
Here is the code which I have at present in my source(spring):
HWND hWnd = FindWindow (0, L " Call of Duty ® - ship - ");
I would like to make this:
HWND hWnd = FindWindow (0, L " Call of Duty ® - ship - " + ui-> lineEdit-> text ());
But it does not work.*
Can you give me work code ?And in LineEdit he put in his username.
See you what I wants to say ?Thanks to you!
Best regards,
John. -
@John_38 said:
HWND hWnd = FindWindow (0, L " Call of Duty ® - ship - " + ui-> lineEdit-> text ());
But it does not work.*Because you cannot concatenate
const char*
andQString
. UseQString( " Call of Duty ® - ship - %1" ).arg( ui-> lineEdit-> text ())
which you should probably transform intoconst char*
afterwards. -
@John_38 said:
HWND hWnd = FindWindow (0, L " Call of Duty ® - ship - " + ui-> lineEdit-> text ());
Thank to your answer ! :-)
Here is what has to look like my code?:
QString("Call of Duty ® - ship - %1").arg(ui->lineEdit->text()) -
@John_38 said:
@John_38 said:
HWND hWnd = FindWindow (0, L " Call of Duty ® - ship - " + ui-> lineEdit-> text ());
Thank to your answer ! :-)
Here is what has to look like my code?:
QString("Call of Duty ® - ship - %1").arg(ui->lineEdit->text())I don't know about
FIndWindow
signature, I'm assuming it'sconst char*
, therefore your line should readHWND hWnd = FindWindow (0, QString("Call of Duty ® - ship - %1").arg(ui->lineEdit->text()).toLocal8Bit().constData());
EDIT: If you want help, please give more detail as "it does ot work" doesn't give us much information. My crystal ball is currently unavailable for repairs...
-
@JohanSolo said:
HWND hWnd = FindWindow (0, QString("Call of Duty ® - ship - %1").arg(ui->lineEdit->text()).toLocal8Bit().constData());
I have test your code.
I have this error: http://prntscr.com/bu9r6r -
Maybe toStdWString would help...
-
@John_38 said:
HWND hWnd = FindWindow (0, QString("Call of Duty ® - ship - %1").arg(ui->lineEdit->text()).toLocal8Bit().constData());
-
I'm sorry, but I have no idea about what is this LPCWSTR type is... Therefore I cannot give you any hints on how to convert QString to this type.
-
I have found !!!!
Big thank to @JohanSolo !
Code: HWND hwnd = FindWindow (0, QString("Call of Duty® - ship - %1").arg(ui->lineEdit->text()).toStdWString().c_str()); -
@John_38 said:
I have found !!!!
Big thank to @JohanSolo !
Code: HWND hwnd = FindWindow (0, QString("Call of Duty® - ship - %1").arg(ui->lineEdit->text()).toStdWString().c_str());Good job! You're welcome.