This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "cpptest.h" | |
| #include <QtWidgets/QApplication> | |
| #include <iostream> | |
| #include <QDebug> | |
| class MyClass | |
| { | |
| public: | |
| static int i; | |
| MyClass() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| QString().toLocal8Bit().data() //可以用 | |
| QString().toStdString().c_str() //不能用 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <afx.h> //解决错误:WINDOWS.H already included. MFC apps must not #include <windows.h> (main.cpp) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| QPushButton#transparentButton{ | |
| background:transparent; | |
| } | |
| QPushButton#menuButton{ | |
| background:transparent; | |
| } | |
| QPushButton#menuButton::menu-indicator{ | |
| image:None; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| http://www.devbean.net/2014/04/about-qstring-tostdstring/ | |
| // 1 | |
| QString str = "Hello, world!"; | |
| auto cStr = str.toStdString().c_str(); | |
| qDebug() << "1:" << cStr; | |
| // 2 | |
| std::string sstr = str.toStdString(); | |
| auto cStr2 = sstr.c_str(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| C++ 11 在 Qt 5 中的应用 | |
| 参考原文:http://woboq.com/blog/cpp11-in-qt5.html | |
| C++ 11 现在已经是 C++ 标准,也就没有理由不在新的应用中使用。Qt 4.8 是第一个支持 C++ 11 特性的 Qt 版本,不过这里,我们首先介绍的是,Qt 5 中如何结合使用 C++ 11。至于 Qt 4.8,我们会在后续文章中进行阐述。 | |
| 显而易见的是,比起 Qt 4.8,Qt 5 利用了更多的 C++ 11 新特性。下面我们来一个个见识一下: | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 由于Qt是一个跨平台的开发库,为了与不同平台上的编译器配合,它定义了一个中间类QMetaObject,该类的作用是存放有关信号/反应槽以及对象自身的信息。这个类是Qt内部使用的,用户不应去使用它。 | |
| 以下是QMetaObject的定义(为了浏览方便,删除了一部分次要代码): | |
| 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; /* 反应槽的数量 */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| mainLayout=newQVBoxLayout(this); | |
| mainLayout->setMargin(30); //表示控件与窗体的左右边距 | |
| mainLayout->setSpacing(40); //表示各个控件之间的上下间距 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| http://blog.csdn.net/xj626852095/article/details/10374659 | |
| 今天在使用addStretch,布局的时候,发现addStretch竟然是可以平均分配的,有意思。比如: | |
| QVBoxLayout *buttonLayout = new QVBoxLayout; | |
| buttonLayout->addStretch(1); | |
| buttonLayout->addWidget(Button1); | |
| buttonLayout->addStretch(1); | |
| buttonLayout->addWidget(Button2); | |
| buttonLayout->addStretch(1); | |
| buttonLayout->addWidget(Button3); |