Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. The Lounge
  4. [HELP] C++ VS to QT
Forum Updated to NodeBB v4.3 + New Features

[HELP] C++ VS to QT

Scheduled Pinned Locked Moved Unsolved The Lounge
12 Posts 3 Posters 4.0k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • John_38J Offline
    John_38J Offline
    John_38
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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());
      

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • John_38J Offline
        John_38J Offline
        John_38
        wrote on last edited by John_38
        #3

        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.

        1 Reply Last reply
        0
        • JohanSoloJ Offline
          JohanSoloJ Offline
          JohanSolo
          wrote on last edited by
          #4

          @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* and QString. Use QString( " Call of Duty ® - ship - %1" ).arg( ui-> lineEdit-> text ()) which you should probably transform into const char* afterwards.

          `They did not know it was impossible, so they did it.'
          -- Mark Twain

          John_38J 1 Reply Last reply
          0
          • JohanSoloJ JohanSolo

            @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* and QString. Use QString( " Call of Duty ® - ship - %1" ).arg( ui-> lineEdit-> text ()) which you should probably transform into const char* afterwards.

            John_38J Offline
            John_38J Offline
            John_38
            wrote on last edited by
            #5

            @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())

            JohanSoloJ 1 Reply Last reply
            0
            • John_38J John_38

              @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())

              JohanSoloJ Offline
              JohanSoloJ Offline
              JohanSolo
              wrote on last edited by JohanSolo
              #6

              @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's const char*, therefore your line should read

              HWND 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...

              `They did not know it was impossible, so they did it.'
              -- Mark Twain

              1 Reply Last reply
              1
              • John_38J Offline
                John_38J Offline
                John_38
                wrote on last edited by
                #7

                @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

                1 Reply Last reply
                0
                • JohanSoloJ Offline
                  JohanSoloJ Offline
                  JohanSolo
                  wrote on last edited by
                  #8

                  Maybe toStdWString would help...

                  `They did not know it was impossible, so they did it.'
                  -- Mark Twain

                  1 Reply Last reply
                  0
                  • John_38J Offline
                    John_38J Offline
                    John_38
                    wrote on last edited by
                    #9

                    @John_38 said:

                    HWND hWnd = FindWindow (0, QString("Call of Duty ® - ship - %1").arg(ui->lineEdit->text()).toLocal8Bit().constData());

                    Oh :/
                    http://prntscr.com/bu9zox

                    1 Reply Last reply
                    0
                    • JohanSoloJ Offline
                      JohanSoloJ Offline
                      JohanSolo
                      wrote on last edited by
                      #10

                      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.

                      `They did not know it was impossible, so they did it.'
                      -- Mark Twain

                      1 Reply Last reply
                      0
                      • John_38J Offline
                        John_38J Offline
                        John_38
                        wrote on last edited by
                        #11

                        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());

                        JohanSoloJ 1 Reply Last reply
                        0
                        • John_38J John_38

                          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());

                          JohanSoloJ Offline
                          JohanSoloJ Offline
                          JohanSolo
                          wrote on last edited by
                          #12

                          @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.

                          `They did not know it was impossible, so they did it.'
                          -- Mark Twain

                          1 Reply Last reply
                          0

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved