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

  • SEARCH
  • Home
  • 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 9248541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:58:02+00:00 2026-06-18T09:58:02+00:00

Assume I have a main window. The main window has some child windows, including

  • 0

Assume I have a main window. The main window has some child windows, including a log window to log what happens and a number of operating windows to operate a user’s data. After each operation in the operating window, I want to log it in the log window. There are several ways to implement it.

  1. Put a pointer pointing to the log window in the operating windows. To do this, I think the operating window is not so reusable since it is bound to a pointer. Someday if I don’t want logging, I need to delete it. Also, this way may take a little more memory. In addition, if the operating window is the main window’s child’s childe’s child…, I need to transfer the pointer inside one by one.

  2. Make the main window to be a singleton and add a public log function to it. When I need logging, I just call like MainWindow::Inheritance()->Log(theInformation). But what happens if someday I have 2 main windows.

Any good suggestion for the problem. Thanks a lot!

  • 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-18T09:58:03+00:00Added an answer on June 18, 2026 at 9:58 am

    I think the right solution is to put the logging data into an entirely separate class, whose purpose is only to store and retrieve (and truncate, and save, and…) log information. All of your other windows, classes, etc that need to log the data would then need access to the single log class pointer.

    logSystem->log("my friend is blue");
    

    Now, whether logSystem is a global or an object passed to each class during initialization is up to you. Any there are many camps of “globals are evil” and “globals are helpful” people to help you with this separate question.

    Then, in your logging window, you simply only need retrieve the logged data and display it.

     // Qt, C++-11 pseudo-api
    foreach(String log, logMessages) {
        myListBox->append(log);
    }
    

    Another advantage of this approach is that you can open and close (create and destroy) the log window and still not loose the data itself. Yes, you could also hide the log window or other trickery, but being able to completely destroy and recreate it seems much cleaner. Not to mention, by separating out the log data from the log window, you can later create two windows showing two different sets of logging data. [Assuming you didn’t use that global for the logging data, mentioned above.]

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

Sidebar

Related Questions

I have a main window which has the UITabViewController as its root controller. I
I have some submenu inserted as Window item submenu of Main Menu I have
Let's assume I have a main script, main.py, that imports another python file with
Assume you have a function read_key and normally it does some stuff. You someone
Creating a popup window from main page with window.open, the child/popup page uses the
within my current project file I have a user control that has a storyboard
All, I have some complex C# code (Windows Forms) that is heavily embedded with
I have a windows app which has MySQL backend. I have wampserver installed on
I have a problem that has been bothering me for a while. Each child
Assume I have two tables, Student Test Id Name TestId Type StudentId -- ----

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.