Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Accessing QTextEdit from another program
QtWS25 Last Chance

Accessing QTextEdit from another program

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 Posters 4.5k Views
  • 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.
  • S Offline
    S Offline
    seawater
    wrote on 21 Jan 2014, 16:15 last edited by
    #1

    I have a program written in C++ using QTextEdit. I have another program written in C#, which I need to access a QTextEdit that is in the C++ program. From C#, I am able to find the parent window with FindWindow api call but cannot find the child window with FindWindowEx. My objective when finding the child window was then get the text of the QTextEdit box. It looks like QWidget does not allow messages using SendMessageA and WM_GETTEXT. Is there another way to get the text from QTextEdit from a C# program?

    Thanks Before Hand

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mcosta
      wrote on 21 Jan 2014, 16:26 last edited by
      #2

      Hi,

      this question isn't Qt related.
      A solution (if exists) must be searched in Windows API.

      Hi

      Once your problem is solved don't forget to:

      • Mark the thread as SOLVED using the Topic Tool menu
      • Vote up the answer(s) that helped you to solve the issue

      You can embed images using (http://imgur.com/) or (http://postimage.org/)

      1 Reply Last reply
      0
      • S Offline
        S Offline
        seawater
        wrote on 21 Jan 2014, 17:14 last edited by
        #3

        I disagree, a normal textbox uses FindWindowEx to reveal itself. Even though QWidget reveals itself with FindWindow. QTextEdit does not use the FindWindowEx to reveal itself. It is definitely not a Windows API issue, it is an issue with the particular way that QTextEdit behaves.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mcosta
          wrote on 22 Jan 2014, 09:02 last edited by
          #4

          Hi,

          what I mean is that there's no solution using Qt API.
          If you want you can try to open a Issue Request on QT Bug Report.

          P.S. what do you mean with normal textbox ?

          Once your problem is solved don't forget to:

          • Mark the thread as SOLVED using the Topic Tool menu
          • Vote up the answer(s) that helped you to solve the issue

          You can embed images using (http://imgur.com/) or (http://postimage.org/)

          1 Reply Last reply
          0
          • S Offline
            S Offline
            seawater
            wrote on 22 Jan 2014, 11:41 last edited by
            #5

            Thank you for your help. Normal textbox would be a textbox created with the standard windows controls in Microsoft Visual Studio.

            Regarding the suggestion you made to try a microsoft forum, it has already been attempted and the issue was pointed back to qt:

            http://social.msdn.microsoft.com/Forums/vstudio/en-US/061413af-04a8-404e-a824-f43f7614ed5f/reading-text-in-third-party-software-to-visual-studio-2010-express?forum=vbgeneral

            1 Reply Last reply
            0
            • S Offline
              S Offline
              seawater
              wrote on 22 Jan 2014, 14:42 last edited by
              #6

              I am going to start putting my progress so far in case someone can help me. So far I understand I need to make a reference to the dll's used by Qt in C#:

              [DllImport("QtCore4.dll")]

              Now I need to figure out how to receive data from QTextEdit...

              1 Reply Last reply
              0
              • D Offline
                D Offline
                daemon777
                wrote on 22 Jan 2014, 17:21 last edited by
                #7

                I dont know if WinAPI has a function to list all elements of a window. But if there is a function like this than you could simply read all of these values one time, watch the values manually and find out this way how the Edit-Box is called.

                I guess that the WinAPI-Control-Elements are not named the same like the abstract Qt-Elements.

                This way you wouldnt need to import Qt-Stuff. Or do you need a more generic solution?

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  seawater
                  wrote on 23 Jan 2014, 03:42 last edited by
                  #8

                  If you see link above, it has already been attempted using windows api and your suggestion (using the FindWindow/FindWindowEx api's). It finds the handle to the QWidget (using FindWindow) but then it does not find any child textbox handles for QTextEdit (using FindWindowEx). If it was a standard windows textbox (Using Microsoft Visual Studio with the common controls), it finds it using FindWindowEx as it normally should. That is when I thought of using the QtCore4.dll or similar Qt dll. From there maybe something with QProcess can be called to get the text from a QTextEdit textbox?

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    seawater
                    wrote on 24 Jan 2014, 21:10 last edited by
                    #9

                    I was able to resolve this using SendKeys command, select of all text (CTRL-A) and then a copy (CTRL-C) to the clipboard. I then retrieved the text from the clipboard into my C# program. Here is the code in case anyone is interested: (The only caveat is that the application cannot be minimized, even then there might be a way to maximize the application before sending the commands) Note: If you have more than one QTextEdit box, you might need to send some tab commands using SendKeys.SendWait("{TAB}") before you send the CTRL commands.
                    @
                    [DllImport("user32.dll")]
                    public static extern bool SetForegroundWindow(IntPtr hWnd);

                    public void getAppData()
                    {

                    // Get AppName handle
                    System.Diagnostics.Process[] p = System.Diagnostics.Process.GetProcessesByName("AppName"); //search for process
                    if (p.Length > 0) //check if window was found
                    {
                    SetForegroundWindow(p[0].MainWindowHandle); //bring window handle to foreground
                    }
                    else
                    {
                    MessageBox.Show("Error: Please make sure AppName is running");
                    }

                    // Wait 500 milliseconds
                    System.Threading.Thread.Sleep(500);

                    // Send CTRL-A (Select All) command to AppName to select all text
                    SendKeys.SendWait("^(a)");

                    // Send CTRL-C (Copy) command to AppName to send data to clipboard
                    SendKeys.SendWait("^(c)");

                    // Wait 3 seconds before checking clipboard (To give chance to data to move to clipboard)
                    System.Threading.Thread.Sleep(3000);

                    // Copy data from the clipboard
                    string text;
                    try
                    {
                    text = Clipboard.GetText().Trim();
                    }
                    catch
                    {
                    text = Clipboard.GetText().Trim(); // sometimes you have to try again...
                    }

                    // Update Text Data
                    if (text != "")
                    {
                    txtData.Text = text;
                    toolStripStatusLabel1.Text = "Data retrieved from AppName.";
                    }
                    else
                    {
                    toolStripStatusLabel1.Text = "No data retrieved from AppName.";
                    }

                    }
                    @

                    1 Reply Last reply
                    0

                    9/9

                    24 Jan 2014, 21:10

                    • Login

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