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 8732105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:22:39+00:00 2026-06-13T09:22:39+00:00

I’m working with QT. Is there a way to preserve values between slots or

  • 0

I’m working with QT. Is there a way to preserve values between slots or functions in general? Just to keep it simple, let’s say my form has three buttons on a toolbar and a line edit. I need the first button to set the value “1” to a variable, and the second button to set “2” to a variable. The third button takes this variable and shows it inside the line edit.

So if I press the first button and then the third the line edit will show the number “1”. If I press the second button and then the third the line edit will show the number “2”. Basically this would make third button’s slot look up the variable that was set by either the first or the second button and then display it. I realize this isn’t the perfect example, but I think it illustrates the concept.

The way’s I’ve tried to think to do it are:

  1. They way I remember from a VB class I took in school… Create a hidden line edit and store the value there until I need it.
    Sadly this will mean lots and lots of hidden line edits on a complex project. Yuck.

  2. Create a global variable in the int main() function and set that variable across all the functions. That can get confusing and anything can access it. So that can be messy.

  3. I’ve noticed that QT for a desktop application appears to have a class called “ui”. I’ve thought of creating my own class with a getter and setter and inheriting everything out of ui…
    I believe this would work but it seems like overkill.

  4. Save the information in a tmp file and read it.
    This seems like it could also be a pain when I just need short term variables.

Is there a simple way to accomplish this task?

  • 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-13T09:22:40+00:00Added an answer on June 13, 2026 at 9:22 am

    You can use a QSignalMapper and connect the first and second buttons to it:

    signalMapper = new QSignalMapper(parent);
    connect(firstButton, SIGNAL(clicked()), signalMapper, SLOT(map()));
    connect(secondButton, SIGNAL(clicked()), signalMapper, SLOT(map()));
    signalMapper->setMapping(firstButton, 1);
    signalMapper->setMapping(firstButton, 2);
    

    You then connect signalMapper‘s mapped(int) signal to your slot:

    connect(signalMapper, SIGNAL(mapped(int)), yourObj, SLOT(yourSlot(int)));
    

    When the first button is clicked, your slot will be called with the value 1 as its argument. When the second button is clicked, 2 will be passed to your slot. You can then save the passed value wherever you like (like in a member variable of yourObj.)

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

Sidebar

Related Questions

Let's say I'm outputting a post title and in our database, it's Hello Y’all
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I'm working with an upstream system that sometimes sends me text destined for HTML/XML

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.