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.1k 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 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