The Meta-Object System Signals & Slots 信号槽机制
应用:
timhul/ClassicSim: An event-driven simulation tool written in C++ for World of Warcraft Classic. https://github.com/timhul/ClassicSim
ClassicSim/ClassicSimControl.cpp at master · timhul/ClassicSim https://github.com/timhul/ClassicSim/blob/master/GUI/ClassicSimControl.cpp
#pragma once #include <QMap> #include <QObject> #include <QSet> #include <QVariant> #include <QVector> #include "EnchantName.h" class ActiveItemStatFilterModel; class AvailableItemStatFilterModel; class BuffBreakdownModel; class BuffModel; class Character; class CharacterDecoder; class CharacterEncoder; class CharacterTalents; class CombatRoll; class DamageMetersModel; class DebuffBreakdownModel; class DebuffModel; class EnchantModel; class Engine; class EngineBreakdownModel; class EquipmentDb; class Item; class ItemModel; class ItemTypeFilterModel; class MeleeDamageAvoidanceBreakdownModel; class MeleeDamageBreakdownModel; class NumberCruncher; class ProcBreakdownModel; class Race; class RaidControl; class RandomAffixes; class RandomAffixModel; class ResourceBreakdownModel; class RotationExecutorBreakdownModel; class RotationExecutorListModel; class RotationModel; class ScaleResult; class ScaleResultModel; class SimControl; class SimScaleModel; class SimSettings; class SimulationThreadPool; class Target; class TemplateCharacterModel; class ThreatBreakdownModel; class WeaponModel; class ClassicSimControl : public QObject { Q_OBJECT public: ClassicSimControl(QObject* parent = nullptr); ~ClassicSimControl(); void save_settings(); /* Character */ Q_PROPERTY(QString classColor READ get_class_color NOTIFY classChanged) Q_PROPERTY(QString className READ get_class_name NOTIFY classChanged) Q_PROPERTY(QString raceName READ get_race_name NOTIFY raceChanged) Q_PROPERTY(bool isAlliance READ get_is_alliance NOTIFY factionChanged) Q_PROPERTY(bool isHorde READ get_is_horde NOTIFY factionChanged) Q_INVOKABLE void selectRace(const QString& race_name); Q_INVOKABLE void selectFaction(const int faction); Q_INVOKABLE bool raceAvailable(const QString& race_name); /* End of Character */ /* Talents */ Q_PROPERTY(int talentPointsRemaining READ get_talent_points_remaining NOTIFY talentsUpdated) Q_PROPERTY(QString leftTalentTreeBackground READ getLeftBackgroundImage NOTIFY classChanged) Q_PROPERTY(QString midTalentTreeBackground READ getMidBackgroundImage NOTIFY classChanged) Q_PROPERTY(QString rightTalentTreeBackground READ getRightBackgroundImage NOTIFY classChanged) Q_PROPERTY(int leftTreePoints READ get_left_talent_tree_points NOTIFY talentsUpdated) Q_PROPERTY(int midTreePoints READ get_mid_talent_tree_points NOTIFY talentsUpdated) Q_PROPERTY(int rightTreePoints READ get_right_talent_tree_points NOTIFY talentsUpdated) Q_PROPERTY(QString talentAllocation READ get_formatted_talent_allocation NOTIFY talentsUpdated) Q_INVOKABLE QString getIcon(const QString& tree_position, const QString& talent_position) const; Q_INVOKABLE bool showPosition(const QString& tree_position, const QString& talent_position) const; Q_INVOKABLE bool showBottomArrow(const QString& tree_position, const QString& talent_position) const; Q_INVOKABLE bool showRightArrow(const QString& tree_position, const QString& talent_position) const; Q_INVOKABLE QString getBottomArrow(const QString& tree_position, const QString& talent_position) const; Q_INVOKABLE QString getRightArrow(const QString& tree_position, const QString& talent_position) const; Q_INVOKABLE bool bottomChildAvailable(const QString& tree_position, const QString& talent_position) const; Q_INVOKABLE bool bottomChildActive(const QString& tree_position, const QString& talent_position) const; Q_INVOKABLE bool rightChildAvailable(const QString& tree_position, const QString& talent_position) const; Q_INVOKABLE bool rightChildActive(const QString& tree_position, const QString& talent_position) const; Q_INVOKABLE bool isActive(const QString& tree_position, const QString& talent_position) const; Q_INVOKABLE bool isAvailable(const QString& tree_position, const QString& talent_position) const; Q_INVOKABLE bool isMaxed(const QString& tree_position, const QString& talent_position) const; Q_INVOKABLE bool hasTalentPointsRemaining() const; Q_INVOKABLE QString getRank(const QString& tree_position, const QString& talent_position) const; Q_INVOKABLE QString getMaxRank(const QString& tree_position, const QString& talent_position) const; Q_INVOKABLE void incrementRank(const QString& tree_position, const QString& talent_position); Q_INVOKABLE void decrementRank(const QString& tree_position, const QString& talent_position); Q_INVOKABLE QString getRequirements(const QString& tree_position, const QString& talent_position) const; Q_INVOKABLE QString getCurrentRankDescription(const QString& tree_position, const QString& talent_position) const; Q_INVOKABLE QString getNextRankDescription(const QString& tree_position, const QString& talent_position) const; Q_INVOKABLE QString getTreeName(const QString& tree_position) const; Q_INVOKABLE QString getTalentName(const QString& tree_position, const QString& talent_position) const; Q_INVOKABLE void maxRank(const QString& tree_position, const QString& talent_position); Q_INVOKABLE void minRank(const QString& tree_position, const QString& talent_position); Q_INVOKABLE void clearTree(const QString& tree_position); Q_INVOKABLE void setTalentSetup(const int talent_index); int get_left_talent_tree_points() const; int get_mid_talent_tree_points() const; int get_right_talent_tree_points() const; int get_tree_points(const QString& tree_position) const; QString get_formatted_talent_allocation() const; /* End of Talents */ Q_INVOKABLE void toggleTank(); Q_PROPERTY(bool isTanking READ get_is_tanking NOTIFY tankingChanged) bool get_is_tanking() const; /* Stats */ Q_PROPERTY(unsigned strength READ get_strength NOTIFY statsChanged) Q_PROPERTY(unsigned agility READ get_agility NOTIFY statsChanged) Q_PROPERTY(unsigned stamina READ get_stamina NOTIFY statsChanged) Q_PROPERTY(unsigned intellect READ get_intellect NOTIFY statsChanged) Q_PROPERTY(unsigned spirit READ get_spirit NOTIFY statsChanged) Q_PROPERTY(QString meleeCritChance READ get_melee_crit_chance NOTIFY statsChanged) Q_PROPERTY(QString meleeHitChance READ get_melee_hit_chance NOTIFY statsChanged) Q_PROPERTY(int meleeAttackPower READ get_melee_attack_power NOTIFY statsChanged) Q_PROPERTY(int wpnSkillMh READ get_mainhand_wpn_skill NOTIFY statsChanged) Q_PROPERTY(int wpnSkillOh READ get_offhand_wpn_skill NOTIFY statsChanged) Q_PROPERTY(QString rangedCritChance READ get_ranged_crit_chance NOTIFY statsChanged) Q_PROPERTY(QString rangedHitChance READ get_ranged_hit_chance NOTIFY statsChanged) Q_PROPERTY(int rangedAttackPower READ get_ranged_attack_power NOTIFY statsChanged) Q_PROPERTY(int wpnSkillRanged READ get_ranged_wpn_skill NOTIFY statsChanged) Q_PROPERTY(int spellPower READ get_spell_power NOTIFY statsChanged) Q_PROPERTY(QString spellHitChance READ get_spell_hit_chance NOTIFY statsChanged) Q_PROPERTY(QString spellCritChance READ get_spell_crit_chance NOTIFY statsChanged) Q_PROPERTY(QString displayStatsType READ get_stats_type_to_display NOTIFY displayStatsTypeChanged) Q_SIGNAL void displayStatsTypeChanged(); QString get_stats_type_to_display() const; QString get_attack_mode_as_string() const; unsigned get_ranged_wpn_skill() const; unsigned get_spell_power() const; QString get_spell_hit_chance() const; QString get_spell_crit_chance() const; Q_INVOKABLE void selectDisplayStat(const QString& attack_mode); /* End of Stats */ /* Equipment */ Q_PROPERTY(QString mainhandIcon READ get_mainhand_icon NOTIFY equipmentChanged) Q_PROPERTY(QString offhandIcon READ get_offhand_icon NOTIFY equipmentChanged) Q_PROPERTY(QString rangedIcon READ get_ranged_icon NOTIFY equipmentChanged) Q_PROPERTY(QString headIcon READ get_head_icon NOTIFY equipmentChanged) Q_PROPERTY(QString neckIcon READ get_neck_icon NOTIFY equipmentChanged) Q_PROPERTY(QString shouldersIcon READ get_shoulders_icon NOTIFY equipmentChanged) Q_PROPERTY(QString backIcon READ get_back_icon NOTIFY equipmentChanged) Q_PROPERTY(QString chestIcon READ get_chest_icon NOTIFY equipmentChanged) Q_PROPERTY(QString wristIcon READ get_wrist_icon NOTIFY equipmentChanged) Q_PROPERTY(QString glovesIcon READ get_gloves_icon NOTIFY equipmentChanged) Q_PROPERTY(QString beltIcon READ get_belt_icon NOTIFY equipmentChanged) Q_PROPERTY(QString legsIcon READ get_legs_icon NOTIFY equipmentChanged) Q_PROPERTY(QString bootsIcon READ get_boots_icon NOTIFY equipmentChanged) Q_PROPERTY(QString ring1Icon READ get_ring1_icon NOTIFY equipmentChanged) Q_PROPERTY(QString ring2Icon READ get_ring2_icon NOTIFY equipmentChanged) Q_PROPERTY(QString trinket1Icon READ get_trinket1_icon NOTIFY equipmentChanged) Q_PROPERTY(QString trinket2Icon READ get_trinket2_icon NOTIFY equipmentChanged) Q_PROPERTY(QString projectileIcon READ get_projectile_icon NOTIFY equipmentChanged) Q_PROPERTY(QString relicIcon READ get_relic_icon NOTIFY equipmentChanged) Q_PROPERTY(QString quiverIcon READ get_quiver_icon NOTIFY equipmentChanged) Q_INVOKABLE void setEquipmentSetup(const int equipment_index); Q_SIGNAL void enchantChanged(); Q_INVOKABLE bool hasItemEquipped(const QString& slot_string) const; Q_INVOKABLE bool hasEnchant(const QString& slot_string) const; Q_INVOKABLE bool hasTemporaryEnchant(const QString& slot_string) const; Q_INVOKABLE QString getEnchantEffect(const QString& slot_string) const; Q_INVOKABLE QString getTemporaryEnchantEffect(const QString& slot_string) const; Q_INVOKABLE void applyEnchant(const QString& slot_string, const int enchant_name); Q_INVOKABLE void applyTemporaryEnchant(const QString& slot_string, const int enchant_name); Q_INVOKABLE void clearEnchant(const QString& slot_string); Q_INVOKABLE void clearTemporaryEnchant(const QString& slot_string); EnchantModel* get_mh_enchant_model() const; EnchantModel* get_mh_temporary_enchant_model() const; EnchantModel* get_oh_enchant_model() const; EnchantModel* get_oh_temporary_enchant_model() const; EnchantModel* get_ranged_enchant_model() const; EnchantModel* get_head_legs_enchant_model() const; EnchantModel* get_shoulder_enchant_model() const; EnchantModel* get_back_enchant_model() const; EnchantModel* get_wrist_enchant_model() const; EnchantModel* get_gloves_enchant_model() const; EnchantModel* get_chest_enchant_model() const; EnchantModel* get_boots_enchant_model() const; /* End of Equipment */ /* ItemModel */ ItemModel* get_item_model() const; WeaponModel* get_weapon_model() const; ItemTypeFilterModel* get_item_type_filter_model() const; ActiveItemStatFilterModel* get_active_stat_filter_model() const; AvailableItemStatFilterModel* get_available_stat_filter_model() const; Q_INVOKABLE bool getFilterActive(const int filter) const; Q_INVOKABLE void toggleSingleFilter(const int filter); Q_INVOKABLE void clearFiltersAndSelectSingle(const int filter); Q_INVOKABLE void selectRangeOfFiltersFromPrevious(const int filter); /* End of ItemModel */ /* Random affixes model */ RandomAffixModel* get_random_affix_model() const; Q_INVOKABLE void setRandomAffixesModelId(const int item_id); /* End of Random affixes model */ /* Buffs and debuffs */ BuffModel* get_buff_model() const; DebuffModel* get_debuff_model() const; Q_INVOKABLE void toggleSingleBuff(const QString& buff); Q_INVOKABLE void clearBuffsAndSelectSingleBuff(const QString& buff); Q_INVOKABLE void selectRangeOfBuffs(const QString& buff); Q_INVOKABLE bool buffActive(const QString& buff) const; Q_INVOKABLE void toggleSingleDebuff(const QString& debuff); Q_INVOKABLE void clearDebuffsAndSelectSingleDebuff(const QString& buff); Q_INVOKABLE void selectRangeOfDebuffs(const QString& buff); Q_INVOKABLE bool debuffActive(const QString& debuff) const; Q_INVOKABLE void setBuffSetup(const int buff_index); /* End of Buffs and debuffs */ /* Statistics */ BuffBreakdownModel* get_buff_breakdown_model() const; DebuffBreakdownModel* get_debuff_breakdown_model() const; EngineBreakdownModel* get_engine_breakdown_model() const; MeleeDamageBreakdownModel* get_dmg_breakdown_model() const; MeleeDamageAvoidanceBreakdownModel* get_dmg_breakdown_avoidance_model() const; ProcBreakdownModel* get_proc_breakdown_model() const; ResourceBreakdownModel* get_resource_breakdown_model() const; RotationExecutorBreakdownModel* get_rotation_executor_model() const; RotationExecutorListModel* get_rotation_executor_list_model() const; ScaleResultModel* get_dps_scale_result_model() const; ScaleResultModel* get_tps_scale_result_model() const; ThreatBreakdownModel* get_thrt_breakdown_model() const; TemplateCharacterModel* get_template_character_model() const; Q_SLOT void compile_thread_results(const QString& error); Q_PROPERTY(QString minDps READ get_min_dps NOTIFY statisticsReady) Q_PROPERTY(QString maxDps READ get_max_dps NOTIFY statisticsReady) Q_PROPERTY(QString dpsStdDev READ get_standard_deviation NOTIFY statisticsReady) Q_PROPERTY(QString dpsConfInterval READ get_confidence_interval NOTIFY statisticsReady) Q_PROPERTY(QString engineHandledEventsPerSecond READ get_handled_events_per_second NOTIFY statisticsReady) QString get_handled_events_per_second() const; /* End of Statistics */ /* Target */ Q_PROPERTY(QString creatureType READ get_creature_type NOTIFY creatureTypeChanged) Q_PROPERTY(int targetArmor READ get_target_armor NOTIFY targetUpdated) Q_PROPERTY(int targetBaseArmor READ get_target_base_armor NOTIFY targetUpdated) Q_INVOKABLE void setCreatureType(const QString& creature_type); Q_SIGNAL void targetUpdated(); int get_target_armor() const; int get_target_base_armor() const; Q_INVOKABLE void setTargetBaseArmor(const int armor); /* End of Target */ /* Content phase */ Q_INVOKABLE void setPhase(const int phase); Q_INVOKABLE QString getDescriptionForPhase(const int phase); /* End of Content phase */ /* Rotation */ RotationModel* get_rotation_model() const; Q_INVOKABLE void selectRotation(); Q_INVOKABLE void selectInformationRotation(const int); Q_PROPERTY(QString rotationName READ get_curr_rotation_name NOTIFY rotationChanged) Q_PROPERTY(QString rotationDescription READ get_curr_rotation_description NOTIFY rotationChanged) Q_PROPERTY(QString rotationInfoName READ get_information_rotation_name NOTIFY informationRotationChanged) Q_PROPERTY(QString rotationInfoDesc READ get_information_rotation_description NOTIFY informationRotationChanged) /* End of Rotation */ /* SimSettings */ Q_INVOKABLE void resetDefaultSettings(); Q_PROPERTY(int combatLength READ get_combat_length NOTIFY combatLengthChanged) Q_PROPERTY(int combatIterationsFullSim READ get_combat_iterations_full_sim NOTIFY combatIterationsChanged) Q_PROPERTY(int combatIterationsQuickSim READ get_combat_iterations_quick_sim NOTIFY combatIterationsChanged) Q_PROPERTY(int numThreads READ get_num_threads NOTIFY numThreadsChanged) Q_PROPERTY(int maxThreads READ get_max_threads NOTIFY numThreadsChanged) Q_INVOKABLE void setCombatLength(const int); Q_INVOKABLE void setCombatIterationsFullSim(const int); Q_INVOKABLE void setCombatIterationsQuickSim(const int); Q_INVOKABLE void setNumThreads(const int); Q_SIGNAL void combatLengthChanged(); Q_SIGNAL void combatIterationsChanged(); Q_SIGNAL void numThreadsChanged(); Q_INVOKABLE void selectRuleset(const int); Q_PROPERTY(QString simProgressString READ get_sim_progress_string NOTIFY simProgressChanged) Q_SIGNAL void simProgressChanged(); Q_INVOKABLE void runQuickSim(); Q_INVOKABLE void runFullSim(); Q_SIGNAL void simPersonalResultUpdated(QString dps, QString dpsChange, QString tps, bool positive); Q_SIGNAL void simRaidResultUpdated(QString dps, QString dpsChange, bool positive); SimScaleModel* get_sim_scale_model() const; Q_PROPERTY(int combatProgress READ get_combat_progress NOTIFY combatProgressChanged) Q_PROPERTY(bool simInProgress READ get_sim_in_progress NOTIFY simProgressChanged) int get_combat_progress() const; bool get_sim_in_progress() const; Q_SIGNAL void combatProgressChanged() const; /* End of SimSettings */ /* Raid setup */ Q_INVOKABLE void selectPartyMember(const int party, const int member); Q_INVOKABLE void clearPartyMember(const int party, const int member); Q_INVOKABLE QVariantMap partyMemberInfo(const int party, const int member); Q_INVOKABLE void selectTemplateCharacter(QString template_char); Q_SIGNAL void partyMembersUpdated(); Q_SIGNAL void selectedPartyMemberChanged(); DamageMetersModel* get_damage_meters_model(); /* End of Raid setup */ /* GUI initialization */ Q_INVOKABLE QString getStartWindow() const; Q_INVOKABLE void changeActiveWindow(const QString& active_window); Q_INVOKABLE int getCurrentRuleset() const; Q_INVOKABLE int getCurrentCreatureType() const; Q_INVOKABLE int getContentPhase() const; /* End of GUI initialization */ bool simulating = false; QString curError; signals: void tankingChanged(); void classChanged(); void raceChanged(); void factionChanged(); void talentsUpdated(); void statsChanged(); void equipmentChanged(); void tooltipChanged(); void statisticsCleared(); void statisticsReady(); void creatureTypeChanged(); void filtersUpdated(); void equipmentSlotSelected(); void rotationChanged(); void informationRotationChanged(); public slots: void update_progress(double percent); public: int get_talent_points_remaining() const; QString get_class_color() const; QString get_class_name() const; QString get_race_name() const; bool get_is_alliance() const; bool get_is_horde() const; void reset_race(Character* pchar); QString get_creature_type() const; QString getLeftBackgroundImage() const; QString getMidBackgroundImage() const; QString getRightBackgroundImage() const; unsigned get_strength() const; unsigned get_agility() const; unsigned get_stamina() const; unsigned get_intellect() const; unsigned get_spirit() const; QString get_melee_crit_chance() const; QString get_melee_hit_chance() const; QString get_ranged_crit_chance() const; QString get_ranged_hit_chance() const; unsigned get_melee_attack_power() const; unsigned get_ranged_attack_power() const; unsigned get_mainhand_wpn_skill() const; unsigned get_offhand_wpn_skill() const; QString get_curr_rotation_name() const; QString get_curr_rotation_description() const; QString get_information_rotation_name() const; QString get_information_rotation_description() const; int get_combat_iterations_full_sim() const; int get_combat_iterations_quick_sim() const; int get_combat_length() const; int get_num_threads() const; int get_max_threads() const; QString get_mainhand_icon() const; QString get_offhand_icon() const; QString get_ranged_icon() const; QString get_head_icon() const; QString get_neck_icon() const; QString get_shoulders_icon() const; QString get_back_icon() const; QString get_chest_icon() const; QString get_wrist_icon() const; QString get_gloves_icon() const; QString get_belt_icon() const; QString get_legs_icon() const; QString get_boots_icon() const; QString get_ring1_icon() const; QString get_ring2_icon() const; QString get_trinket1_icon() const; QString get_trinket2_icon() const; QString get_projectile_icon() const; QString get_relic_icon() const; QString get_quiver_icon() const; QString get_initial_upper_case_rest_lower_case(const QString&) const; void set_character(Character* pchar); void run_sim(const bool full_sim); void calculate_displayed_dps_value(); void update_displayed_dps_value(const double new_dps_value, const double new_tps_value); void update_displayed_raid_dps_value(const double new_dps_value); QString get_sim_progress_string() const; QString get_min_dps() const; QString get_max_dps() const; QString get_standard_deviation() const; QString get_confidence_interval() const; Character* load_character(const QString& class_name); Character* load_character_from_str(const QByteArray& data); Character* get_new_character(const QString& class_name); void save_user_setup(Character* pchar); void save_configuration(); void load_configuration(); void activate_configuration(const QStringRef& name, const QString& value); EquipmentDb* equipment_db; RandomAffixes* random_affixes_db; CharacterEncoder* character_encoder; CharacterDecoder* character_decoder; SimulationThreadPool* thread_pool; SimControl* sim_control; SimSettings* sim_settings; Target* target; RaidControl* raid_control; NumberCruncher* number_cruncher; QMap<QString, Character*> chars; QMap<QString, Race*> races; QSet<QString> supported_classes; QMap<QString, RaidControl*> raid_controls; QVector<QVector<QVariantMap>> raid_setup; Character* current_char; ItemModel* item_model; ActiveItemStatFilterModel* active_stat_filter_model; AvailableItemStatFilterModel* available_stat_filter_model; ItemTypeFilterModel* item_type_filter_model; WeaponModel* weapon_model; BuffModel* buff_model; DamageMetersModel* damage_meters_model; DebuffModel* debuff_model; RotationModel* rotation_model; BuffBreakdownModel* buff_breakdown_model; DebuffBreakdownModel* debuff_breakdown_model; EngineBreakdownModel* engine_breakdown_model; MeleeDamageBreakdownModel* damage_breakdown_model; MeleeDamageAvoidanceBreakdownModel* damage_avoidance_breakdown_model; ProcBreakdownModel* proc_breakdown_model; ResourceBreakdownModel* resource_breakdown_model; RotationExecutorListModel* rotation_executor_list_model; SimScaleModel* sim_scale_model; ScaleResultModel* dps_scale_result_model; ScaleResultModel* tps_scale_result_model; ScaleResult* dps_distribution; ThreatBreakdownModel* threat_breakdown_model; TemplateCharacterModel* template_character_model; EnchantModel* mh_enchants; EnchantModel* mh_temporary_enchants; EnchantModel* oh_enchants; EnchantModel* oh_temporary_enchants; EnchantModel* ranged_enchants; EnchantModel* head_legs_enchants; EnchantModel* shoulder_enchants; EnchantModel* back_enchants; EnchantModel* wrist_enchants; EnchantModel* gloves_enchants; EnchantModel* chest_enchants; EnchantModel* boots_enchants; RandomAffixModel* random_affixes; double last_personal_sim_result {0.0}; double last_personal_sim_result_tps {0.0}; double last_raid_sim_result {0.0}; double last_engine_handled_events_per_second {0.0}; bool sim_in_progress; double sim_percent_completed {0.0}; int current_party {1}; int current_member {1}; QString active_window; QString stats_type_to_display; QVector<Race*> raid_member_races; };
Qt 6.0正式发布了_Qt中国的博客-CSDN博客 https://blog.csdn.net/Qt_China/article/details/111034861
核心库和API
我们为Qt Core做了大量工作,因为它是实现Qt最核心部分的模块,我们做了许多改进。 列举几个最重要的例子:
- 新的属性和绑定系统:该系统将绑定的概念(使QML在Qt5取得了巨大成功)带回到了Qt的核心,并使其可用于C ++。
- 字符串和Unicode:Qt 5时我们朝着使Qt与Unicode完全对齐的方向发展,所以许多工作已经完成。 但是,剩下的一些部分已在Qt 6中得到了清理。更多详细信息将很快在另一篇博文中介绍。
- QList在Qt 5中经常受到批评,因为它是对存储在其中的大于指针的对象进行堆分配,这给内存分配器带来了很大的压力。 在Qt 6中,我们对此进行了更改,并将QList和QVector统一为一个类。 有关更多详细信息,请参见我们在Qt 6中有关QList的博客。
- QMetaType和QVariant是Qt元对象系统的基础。 没有QMetaType,信号和插槽将无法实现,动态调用需要QVariant。 Qt 6中的这两个类几乎完全重写,您可以在此处找到详细信息。
Qt中与图形无关的其他部分也完成了显著的改进。比如完成了Qt Concurrent的大量重写,使得多线程应用程序的开发更加简单。我们对Qt Network也做了大幅整理和改进(具体内容请参考这篇博文)
Qt 6.0 Released https://www.qt.io/blog/qt-6.0-released
Core libraries and APIs
Much work has gone into Qt Core, as it is the module that implements the most central parts of Qt. We've gone through many areas there and made improvements. To name some of the most central ones:
- The new property and binding system: This system now brings the concept of bindings that made QML such a huge success in Qt 5 available from C++.
- Strings and Unicode: With Qt 5, we started aligning Qt fully with Unicode, where we completed a lot of the work, but a few items remained that we now cleaned up for Qt 6. More details will come in a separate blog post later on.
- QList has been a class that was often criticized in Qt 5, as it was heap allocating objects stored in there that were larger than a pointer, leading to pressure on heap allocation methods. In Qt 6, we changed this and unified QList and QVector into one class. See our blog post about QList in Qt 6 for details.
- QMetaType and QVariant are fundamental to how our Qt’s meta-object system works. Signals and slots would not be possible without QMetaType and QVariant is required for dynamic invocations. Those two classes got an almost complete rewrite with Qt 6, and you can read about the details here.
Other parts of Qt that are not related to graphics have also seen large changes. For example, Qt Concurrent has undergone an almost complete rewrite and now makes development of multi-threaded applications more effortless than ever. Qt Network has seen lots of clean-up and improvements. See this blog post for details.
The Meta-Object System | Qt Core 6.0.1 https://doc.qt.io/qt-6/metaobjects.html
Signals & Slots | Qt Core 6.0.1 https://doc.qt.io/qt-6/signalsandslots.html
https://doc.qt.io/qt-6/signalsandslots.html
Q_PROPERTY:这个宏用于声明一个可以被 QML 访问的属性,包括它的类型、getter/setter、发生变化时会出发的信号。一般来说哪怕对于 QML 端是只读的属性,也需要添加一个信号。这在宏的 NOTIFY 项之后声明。
当这个信号被触发的时候,QML 端会重新渲染所有依赖于这个属性值的界面组件。
Q_INVOKABLE:这个宏用于声明一个可以被 QML 调用的方法。
// 伪代码 以此代码为例讨论
connect(sender, signal, receiver, slot, connectionType);
QT中简单的emit使用_CSDN_dyq111的博客-CSDN博客_emit https://blog.csdn.net/CSDN_dyq111/article/details/107179722
***A类的.h中*** class A { public: ***//公共的行为或属性*** void Dome(); ***//这个是演示的例子属性*** private: signals: ***//信号*** void AmySignal(); ***//在信号的里面加上一个你自定义的信号.*** slots: ***//槽*** }; ***B类的.h中*** class B { public: ***//公共的行为或属性*** private: signals: ***//信号*** slots: ***//槽*** void BmySlot1(); ***//在B类中填一个你想要的现象的定义。*** }; ***A类的cpp*** void A::Dome() { B = new B; ******//在这里要先将B类实例化*** ***//信号与槽需要实例化对象****** connect(this, SIGNAL(mySignal()), B, SLOT( BmySlot1())); ***//将A类的信号和B类的槽函数链接起来*** emit void AmySignal(); ***//发出信号*** } ***B类的cpp*** void B::BmySlot1() { printf("hello world\n"); ***//实现*** } 3.这样就可以在A中对B使用信号了。
Qt emit的使用 - 我是张洪铭我是熊博士 - 博客园 https://www.cnblogs.com/azbane/p/8651810.html
1. 假设现在我定义了一个类A,现在想在A的一个函数void A::function1()当中的结尾处emit一个信号signal1(),然后利用这个信号触发另一个类B进行某项操作void B::function2(),请问connect应该如何书写呢(尤其是sender和SIGNAL参数)?另外,对于类A和类B,有什么特殊要求吗?
KEY:
比如在一个QMainwindow中,包含类A,B的头文件,是的类A,和类B可见,定义一个类A *a,和一个类B *b,(当然要分配空间).你就可以这么connect他们.
connect(a,SIGNAL(signal1()),b,SLOT(function2()));
对于A,B两个类出来都必须继承于QObject类没其他要求,还有若是类A,B定义在了main()函数中,那么应该使用QObject::connect( )。
QT 中 关键字讲解(emit,signal,slot) - FelixWang - 博客园 https://www.cnblogs.com/felix-wang/p/6212197.html
Qt中的类库有接近一半是从基类QObject上继承下来,信号与反应槽(signals/slot)机制就是用来在QObject类或其子类间通讯的方法。作为一种通用的处理机制,信号与反应槽非常灵活,可以携带任意数量的参数,参数的类型也由用户自定。同时其本身也是类型安全的,任何一个从QObject或其子类继承的用户类都可以使用信号与反应槽。
class Demo : public QObject { Q_OBJECT public: Demo(); int value() const { return val; }; public slots: void setValue( int ); signals: void valueChanged( int ); private: int val; }; 由样例可看到,类的定义中有两个关键字slots和signals,还有一个宏Q_OBJECT。在Qt的程序中如果使用了信号与反应槽就必须在类的定义中声明这个宏,不过如果你声明了该宏但在程序中并没有信号与反应槽,对程序也不会有任何影响,所以建议大家在用Qt写程序时不妨都把这个宏加上。使用slots定义的就是信号的功能实现,即反应槽,例如: void Demo::setValue( int v ) { if ( v != val ) { val = v; emit valueChanged(v); } } 这段程序表明当setValue执行时它将释放出valueChanged这个信号。 以下程序示范了不同对象间信号与反应槽的连接。 Demo a, b; connect(&a, SIGNAL(valueChanged(int)), &b, SLOT(setValue(int))); b.setValue( 11 ); a.setValue( 79 ); b.value(); // b的值将是79而不是原先设的11
class Q_EXPORT QMetaObject { public: QMetaObject( const char * const class_name, QMetaObject *superclass, const QMetaData * const slot_data, int n_slots, const QMetaData * const signal_data, int n_signals); virtual ~QMetaObject(); int numSlots( bool super = FALSE ) const; int numSignals( bool super = FALSE ) const; int findSlot( const char *, bool super = FALSE ) const; int findSignal( const char *, bool super = FALSE ) const; const QMetaData *slot( int index, bool super = FALSE ) const; const QMetaData *signal( int index, bool super = FALSE ) const; QStrList slotNames( bool super = FALSE ) const; QStrList signalNames( bool super = FALSE ) const; int slotOffset() const; int signalOffset() const; static QMetaObject *metaObject( const char *class_name ); private: QMemberDict *init( const QMetaData *, int ); const QMetaData *slotData; QMemberDict *slotDict; const QMetaData *signalData; QMemberDict *signalDict; int signaloffset; int slotoffset; };
void QObject::connectInternal( const QObject *sender, int signal_index,const QObject *receiver,int membcode, int member_index ) { QObject *s = (QObject*)sender; QObject *r = (QObject*)receiver; if ( !s->connections ) { s->connections = new QSignalVec( 7 ); s->connections->setAutoDelete( TRUE ); } QConnectionList *clist = s->connections->at( signal_index ); if ( !clist ) { clist = new QConnectionList; clist->setAutoDelete( TRUE ); s->connections->insert( signal_index, clist ); } QMetaObject *rmeta = r->metaObject(); switch ( membcode ) { case QSLOT_CODE: rm = rmeta->slot( member_index, TRUE ); break; case QSIGNAL_CODE: rm = rmeta->signal( member_index, TRUE ); break; } QConnection *c = new QConnection( r, member_index, rm ? rm->name : "qt_invoke", membcode ); clist->append( c ); if ( !r->senderObjects ) { r->senderObjects = new QObjectList; } r->senderObjects->append( s ); }
void QObject::activate_signal( QConnectionList *clist, QUObject *o ) { if ( !clist ) return; QObject *object; QConnection *c; if ( clist->count() == 1 ) { c = clist->first(); object = c->object(); sigSender = this; if ( c->memberType() == QSIGNAL_CODE ) object->qt_emit( c->member(), o ); else object->qt_invoke( c->member(), o ); } else { QConnectionListIt it(*clist); while ( (c=it.current()) ) { ++it; object = c->object(); sigSender = this; if ( c->memberType() == QSIGNAL_CODE ) object->qt_emit( c->member(), o ); else object->qt_invoke( c->member(), o ); } } }
#define slots // slots: in class #define signals protected // signals: in class #define emit // emit signal #define SLOT(a) "1"#a #define SIGNAL(a) "2"#a
#define Q_OBJECT \ public: \ virtual QMetaObject *metaObject() const { \ return staticMetaObject(); \ } \ virtual const char *className() const; \ virtual void* qt_cast( const char* ); \ virtual bool qt_invoke( int, QUObject* ); \ virtual bool qt_emit( int, QUObject* ); \ QT_PROP_FUNCTIONS \ static QMetaObject* staticMetaObject(); \ QObject* qObject() { return (QObject*)this; } \ QT_TR_FUNCTIONS \ private: \ static QMetaObject *metaObj;
QMetaObject *Demo::metaObj = 0; void Demo::initMetaObject() { if ( metaObj ) return; if ( strcmp(QObject::className(), "QObject") != 0 ) badSuperclassWarning("Demo","QObject"); (void) staticMetaObject(); } QMetaObject* Demo::staticMetaObject() { if ( metaObj ) return metaObj; (void) QObject::staticMetaObject(); typedef void(Demo::*m1_t0)(int); m1_t0 v1_0 = Q_AMPERSAND Demo::setValue; QMetaData *slot_tbl = QMetaObject::new_metadata(1); QMetaData::Access *slot_tbl_access = QMetaObject::new_metaaccess(1); slot_tbl[0].name = "setValue(int)"; slot_tbl[0].ptr = *((QMember*)&v1_0); slot_tbl_access[0] = QMetaData::Public; typedef void(Demo::*m2_t0)(int); m2_t0 v2_0 = Q_AMPERSAND Demo::valueChanged; QMetaData *signal_tbl = QMetaObject::new_metadata(1); signal_tbl[0].name = "valueChanged(int)"; signal_tbl[0].ptr = *((QMember*)&v2_0); metaObj = QMetaObject::new_metaobject( "Demo", "QObject", slot_tbl, 1, signal_tbl, 1, 0, 0 ); metaObj->set_slot_access( slot_tbl_access ); return metaObj; } // 有信号时即激活对应的反应槽或另一个信号 void Demo::valueChanged( int t0 ) { activate_signal( "valueChanged(int)", t0 ); }