tailieunhanh - Rapid GUI Development with QtRuby phần 6

Tham khảo tài liệu 'rapid gui development with qtruby phần 6', ngoại ngữ, ngữ pháp tiếng anh phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Chapter 5. Take the Plunge Signals and Slots 54 @label @button Label Text clicked setText const QString Figure Slot Connection with mis-matched arguments ment is discarded. However the opposite is not true button Qt label Qt This doesn t work Qt Object connect button SIGNAL clicked label SLOT setText const QString The above code generates the following error which is displayed during runtime QObject connect Incompatible sender receiver arguments Qt PushButton clicked -- Qt Label setText const QString Disconnecting Signals and Slots Signal slot connections can also be disconnected via the same syntax button Qt bar Qt Qt Object connect button SIGNAL clicked bar SLOT clear Perform a disconnection BOOKLEET Report erratum Chapter 5. Take the Plunge Signals and Slots 55 Qt Object disconnect button SIGNAL clicked @bar SLOT clear Tying it all together The power with signals and slots lies in their flexibility. Signals can be used from existing widgets or created in new widgets. New slots can be made in custom widgets that mask internal child widgets. Most importantly these signals and slots cross widget boundaries and allow us to encapsulate child widgets through a parent widget interface. Let s see it in action. Consider this class class MyTimer Qt Widget signals tripped_times_signal int slots timer_tripped_slot def initialize parent super parent timer Qt self label Qt self tripped_times 0 connect timer SIGNAL timeout self SLOT timer_tripped_slot Make the timer trip every second 1000 milliseconds 1000 end def timer_tripped_slot tripped_times 1 The timer has tripped times BOOKLEET Report erratum MyTimer Qt Widget Figure Custom Widget with Signals and Slots Qt Timer is a very convenient class for repeatedly calling a slot at a certain frequency. In most cases a Qt Timer can be accurate to 1 millisecond. emit tripped_times_signal @tripped_times end

TỪ KHÓA LIÊN QUAN
crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.