Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9110081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T03:11:30+00:00 2026-06-17T03:11:30+00:00

I have some code which uses WinAPI to get the title and classname of

  • 0

I have some code which uses WinAPI to get the title and classname of a window from it’s handle using GetWindowTextW and GetClassNameW. I would like to create a unit test for this code using Qt to create a temporary window, run my code against it, and then close the window. However I’m unsure how to go about doing this in a simple way. For example, I could create the window as follows:

#include "QtWidgets\qapplication.h"
#include "QtWidgets\qtextedit.h"
int argc = 1;
char* argv[1];
QApplication app(argc, &argv[0]);
QTextEdit textEdit;
textEdit.show();
app.exec(;)
// Rest of my unit test here

However at that point the QApplication object enters it’s event loop and assumes control of my unit test until I close the window. What is the best way to allow my unit test to continue operating on the window? Should I create a separate thread for the window? Being a unit test, I would like to keep it as simple as possible.

This question is intended to be unit test framework independent, but in case it matters, I’m using UnitTest++.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T03:11:31+00:00Added an answer on June 17, 2026 at 3:11 am

    You won’t be able to create a separate thread, since all Qt gui objects have to be in the main thread, you can only use signals/slot mechanism to interact with gui objects from other threads.

    I think the simplest would be to subclass QTextEdit, implement public slot UnitTest(), and modify your test as follows:

    #include "QtWidgets\qapplication.h"
    #include "QtWidgets\qtextedit.h"
    #include "MyTextEdit.h"
    #include <QTimer>
    
    int argc = 1;
    char* argv[1];
    QApplication app(argc, &argv[0]);
    my_QTextEdit textEdit;
    textEdit.show();
    QTimer::singleShot(&my_QTextEdit,SLOT(UnitTest()),0);
    app.exec();
    

    This gives you an entry point to my_QTextEdit::UnitTest() after QApplication is properly instantiated and event loop is running. Or, you can implement your own class inherited from QObject, create public slot, create that object prior to running app.exec() (passing to it pointer to QTextEdit if necessary) ; and connect to the slot the same way – whatever suits your needs better.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code which uses System.Net.Mail.SmtpClient.Send to send data from a piece of
I have some code, which uses the ExecuteStmt method on the Axapta Object when
I have a user control which uses objects as inner properties (some code is
I have some code which I'm currently using to change the static-IP of a
I have some fairly generic code which uses preprocessor macros to add a certain
I have some class which uses boost singleton. It calls some function from own
I have seen some code which uses the <= operator. Can you explain what
I have below some code in C which uses the fork() system call, but
We have some code which produces an RTF document from a RTF template. It
I have some code which uses a selector in a loop. This works: document.getElementById(new_grouping_+i).value

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.