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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:16:49+00:00 2026-05-31T05:16:49+00:00

I have another problem that I can’t solve I have a following code that

  • 0

I have another problem that I can’t solve

I have a following code that adds a user (first name, last name and age) into a treeview. It all works well except for one small thing: it works well only when you add an user for the first time. When you hit add and then try to add yet another user it will attempt to add 2 users, then 3, 4 and so on, increasing with each addition. Here’s the code that catches the click event:

onClicked (dodajUczBt gui) (dodajUcz gui dbh stores)

and here’s the function dodajUcz that handles the click:

dodajUcz gui dbh stores =
    do  entrySetText (nImie gui) ""
        entrySetText (nNazwisko gui) ""
        entrySetText (nWiek gui) ""
        onClicked (cancelAddUczBt gui) (widgetHide (dodajUzDialog gui))
        onClicked (zapiszUczBtn gui) procADD
        windowPresent (dodajUzDialog gui)
    where procADD = do
            ucz <- getUczestnik
            let store = uczestnicy stores
            New.listStoreAppend store ucz
            dlugosc <- New.listStoreGetSize store
            labelSetText (lblLiczbaUcz gui) $ "Liczba uczestników: "++ show dlugosc 
            widgetHide (dodajUzDialog gui)
            addUser ucz dbh
          getUczestnik = do
                                imie <- entryGetText (nImie gui)
                                nazwisko <- entryGetText (nNazwisko gui)
                                wiek <- entryGetText (nWiek gui)
                                let wiek' = read wiek :: Integer
                                return $ Uczestnik 0 imie nazwisko wiek' False

Uczestnik is an algebraic data type and addUser is a function that adds an Uczestnik into database. gui is also an algebraic data type GUI,that holds all the gui elements created by castToXml

It seems to me that widgetHide is the main problem, because even if you don’t do anything (just open the dialog and then close it) it’ll try to add 2 users the next time you open it.

Any ideas how to solve this problem? Any help would be greatly appreciated 🙂

  • 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-05-31T05:16:49+00:00Added an answer on May 31, 2026 at 5:16 am

    Well, my understanding is that:

    1. To show the dialog again, you call dodajUcz from somewhere else in you code.
    2. Every time you add a user, you hide the dialog (and you request that it’s shown again)
    3. MOST IMPORTANTLY: every time you evaluate (that is, execute) dodajUcz, you install the event handler for the event ‘Clicked’ on zapiszUczBtn AGAIN (using onClicked). When you install an event handler for an event, it stays there forever and will get executed every time the event is triggered. if you install it twice, it’ll get executed twice. In this particular case, after calling dodajUcz twice, the event handler will get executed twice when the event Clicked is triggered on zapiszUczBtn.

      Using onClicked or any other event handler installer won’t remove previous handlers, they get added to the handler stack for that widget and event.

      When you initialise the gui (when you first create it), set the event handlers only once in your code and do not execute that code again. You can pass the gui and the stores as args to procADD then.

      For instance:

      startGUI :: DBH -> IO (GUI, Stores)
      startGUI dbh = do
        gui <- giveMeGUI -- or some other function that returns a gui
        stores <- giveMeStores -- or some other function that returns the stores
        onClicked (cancelAddUczBT gui) (widgetHide (dodaUzDialog gui))
        onClicked (zapiszUczBtn gui) (procADD gui dbh stores)
        return (gui, stores)
      
      dodajUcz gui dbh stores = do
         entrySetText (nImie gui) ""
         entrySetText (nNazwisko gui) ""
         entrySetText (nWiek gui) ""
         windowPresent (dodajUzDialog gui)
      
      procADD gui dbh stores = do
         ...
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

following up on this question , I now have another problem - how can
Following on from a question I posted yesterday about GUIs, I have another problem
I have a problem that can be simplified as follows: I have a particular
I have just solved another problem regarding the same piece of code but I
I have another CSS problem. A layout that escapes me. I could, I suppose,
I have this SearchMenuActivity that has a bunch of options the user can select.
I have div called panel that itself contains another div. When a user clicks
I've been struggling with Zend_Navigation all weekend, and now I have another problem, which
Okay, so I have another question on a prolog homework problem I am struggling
After getting a helpful answer here , I have run into yet another problem:

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.