[commonqt-devel] Comparing QButtons

Stas Boukarev stassats at gmail.com
Mon Sep 16 12:53:46 UTC 2013


Rujia Liu <rujia.liu at gmail.com> writes:

> Hi!
>
> I've create a QMessageBox and tried to use clickedButton() to determine
> which button is clicked, like illustrated in QMessageBox::clickedButton
> ()'s document.
>
> My function:
>
> (defun yes-no-cancel-dialog (text informative-text yes-text no-text
> cancel-text)
>     (with-objects ((message-box (#_new QMessageBox)))
>         (#_setText message-box text)
>         (#_setInformativeText message-box informative-text)
>         (let ((yes-button (#_addButton message-box yes-text
> (#_QMessageBox::YesRole)))
>               (no-button (#_addButton message-box no-text
> (#_QMessageBox::NoRole)))
>               (cancel-button (#_addButton message-box cancel-text
> (#_QMessageBox::RejectRole)))
>               (clicked-button))
>             (#_exec message-box)
>             (setf clicked-button (#_clickedButton message-box))
>             (format t "clicked:~A~%" (#_clickedButton message-box))
>             (format t "clicked:~A~%" yes-button)
>             (format t "clicked:~A~%" no-button)
>             (format t "clicked:~A~%" cancel-button)
>             (cond ((eq clicked-button yes-button) :yes)
>                   ((eq clicked-button no-button) :no)
>                   ((eq clicked-button cancel-button) :cancel)
>                   (t nil)))))
>
> When I click "yes" button, I can see something like:
>
> clicked:#<QPushButton 0x02003E18>
> clicked:#<QPushButton 0x02003E18>
> clicked:#<QPushButton 0x02004098>
> clicked:#<QPushButton 0x02004428>
>
> I tried eq, eql, equal and equalp, none of them return t when comparing
> clicked-button with yes-button. What can I do to compare two pointers?
It's strange that it's not coalesced, I'll look into it.

But in this case, you can just write:

(case (#_exec message-box)
  (0 :yes)
  (1 :no)
  (2 :cancel))

-- 
With best regards, Stas.



More information about the commonqt-devel mailing list