qt4

Using a QStyledItemDelegate on a QListView with QSqlQueryModel

好久不见. 提交于 2019-12-18 03:32:24
问题 I have a QListView, that has a QSqlQueryModel set as its model. How can I use a QStyledItemDelegate in order to customise the QListView's rows' appearence (e.g. show 2 text lines) ? QSqlDatabase db = QSqlDatabase::addDatabase( "QSQLITE" ); db.setDatabaseName( "test.db" ); if( !db.open() ) { qDebug() << db.lastError(); qFatal( "Failed to connect." ); } qDebug( "Connected!" ); QSqlQueryModel *sqlModel = new QSqlQueryModel; sqlModel->setQuery("SELECT * FROM entries"); mListWidget->setModel

QNetworkReply wait for finished

会有一股神秘感。 提交于 2019-12-18 03:22:12
问题 I am using Qt 4.6.3 and the following not-working code QStringList userInfo; QNetworkRequest netRequest(QUrl("http://api.stackoverflow.com/1.1/users/587532")); QNetworkReply *netReply = netman->get(netRequest); // from here onwards not working netReply->waitForReadyRead(-1); if (netReply->isFinished()==true) {userInfo << do sth to reply;} return userInfo; as this function returns an empty QStringList, the app crashes. How to wait until the request has finished and then process the reply

Qt SSL support missing

偶尔善良 提交于 2019-12-18 02:59:11
问题 I've just downloaded Qt (LGPL - Qt SDK for Windows) and when i run some of the demos they complain about Qt not having SSL. How can i get the Qt SDK with SSL enabled? Do i really need to compile it from source to get SSL support? Why is it missing in the version i've downloaded? 回答1: @user261882 answer is only partially correct. He is correct in saying that Qt does not come with SSL support and that you do need to download the OpenSSL libraries. However, the linking process after is much more

Qt SSL support missing

徘徊边缘 提交于 2019-12-18 02:59:03
问题 I've just downloaded Qt (LGPL - Qt SDK for Windows) and when i run some of the demos they complain about Qt not having SSL. How can i get the Qt SDK with SSL enabled? Do i really need to compile it from source to get SSL support? Why is it missing in the version i've downloaded? 回答1: @user261882 answer is only partially correct. He is correct in saying that Qt does not come with SSL support and that you do need to download the OpenSSL libraries. However, the linking process after is much more

Copy directory using Qt

允我心安 提交于 2019-12-18 02:00:16
问题 I want to copy a directory from one drive to another drive. My selected directory contains many sub directories and files. How can I implement the same using Qt? 回答1: void copyPath(QString src, QString dst) { QDir dir(src); if (! dir.exists()) return; foreach (QString d, dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) { QString dst_path = dst + QDir::separator() + d; dir.mkpath(dst_path); copyPath(src+ QDir::separator() + d, dst_path); } foreach (QString f, dir.entryList(QDir::Files)) {

How to create delegate for QTreeWidget?

邮差的信 提交于 2019-12-17 23:08:18
问题 Here is what I'm trying to do (all parents and children must have a close button on the right, in the future, only the hovered item will be able to show the **close ** button): My delegate code: class CloseButton : public QItemDelegate { Q_OBJECT public: CloseButton( QObject* parent = 0 ) : QItemDelegate( parent ) {}; QWidget* createEditor( QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index ) const { if ( index.column() == 1 ) { QToolButton* button = new QToolButton

How to encrypt and decrypt a file with Qt/C++?

拜拜、爱过 提交于 2019-12-17 22:42:44
问题 I want to create a program, which can encrypt and decrypt a complete file with an individual password. Is there any way to manage this in Qt and/or C++ and how? 回答1: I've never used it myself, but I've heard great things about QCA. It's cross platfrom, uses a Qt-style API and Qt datatypes. 回答2: www.cryptopp.com is a very complete C++ library with implementations of most algorithms. The actual program (select file, read, obtain key, encrypt etc) should be piece of cake. 回答3: Old, I know, but

Removing a non empty folder in Qt

房东的猫 提交于 2019-12-17 22:36:07
问题 How to remove a non-empty folder in Qt. 回答1: Recursively delete the contents of the directory first. Here is a blog post with sample code for doing just that. I've included the relevant code snippet. bool removeDir(const QString & dirName) { bool result = true; QDir dir(dirName); if (dir.exists()) { Q_FOREACH(QFileInfo info, dir.entryInfoList(QDir::NoDotAndDotDot | QDir::System | QDir::Hidden | QDir::AllDirs | QDir::Files, QDir::DirsFirst)) { if (info.isDir()) { result = removeDir(info

How to get sender widget with a signal/slot mechanism?

柔情痞子 提交于 2019-12-17 22:34:50
问题 It's possible to bind more than one signal to one slot (isn't?). So, is there a way to understand which widget sends the signal? I'm looking for something like sender argument of events in .NET 回答1: QObject::sender() will do the job. 回答2: Use QObject::sender() in the slot, like in the following Example: void MainWindow::someSetupFunction( void ) { ... connect( _foobarButton, SIGNAL(clicked()), this, SLOT(buttonPressedSlot()) ); } void MainWindow::buttonPressedSlot() { // e.g. check with

emit std::string with qt signal

不想你离开。 提交于 2019-12-17 19:39:56
问题 I am trying to emit standard string with qt signal. The signal will be delivered as queued. I registered the type with qRegisterMetaType , like it says in the qt documentation, but no luck. I am registering it like this qRegisterMetaType<std::string>("std::string") 回答1: You should also do: Q_DECLARE_METATYPE (std::string) Quoting Qt Doc Adding a Q_DECLARE_METATYPE() makes the type known to all template based functions, including QVariant. Note that if you intend to use the type in queued