Category Archives: 编程

编程

C++ 编程易犯错误-类指针成员未初始化

在 C++ 编程过程中,如果类体内声明的数据成员为指针变量,就需要在构造函数中初始化,否则就会出现内在不能为 written 的错误,因此导致程序退出,对于此,编译器并不提示,所以做到使用前初始化还是比较好的。

Posted in C++, 原创 | Tagged , | Leave a comment

QWizard下一步按钮的控制

QWizard是Qt的向导类,在向导过程中,可以通过函数registerField注册字段实现全局访问,而且可以通过4种方法来控制下一步或者完成按钮的可用性: 第一种方法,isComplete函数,其应用于QWizardPage,可控制单个向导页面的“下一步”或者“完成”按钮的可用性,函数如下: bool QWizardPage::isComplete () const[virtual] 下面是isComplete的实现,源码来源于 http://doc.qt.nokia.com/qq/qq22-qwizard.html#validatebeforeitstoolate 首先重新实现QWizardPage::isComplete()函数 bool SailingPage::isComplete() const { return field("sailing").toDate().dayOfWeek() != Qt::Sunday; } 连接输入框或者其他需要监视的对象的信号与QWizardPage::completeChanged ()信号。 connect(sailing, SIGNAL(selectionChanged()), this, SIGNAL(completeChanged())); 当然也可以自己执行QWizardPage::completeChanged ()信号,即自行编写完成检查函数后执行信号: emit completeChanged() 第二种方法,hasAcceptableInput函数,用于QLineEdit,如果hasAcceptableInput为false,则按钮会变灰。 bool hasAcceptableInput () const 第三种方法,registerField函数,第一个参数name后加星号,例如field*,就可以保证如果此区域不填写,下一步按钮将始处于灰色状态。 void QWizardPage::registerField ( const QString & … Continue reading

Posted in Qt, 原创 | Tagged , , , | Leave a comment

dokuwiki中文文件名及sitemap乱码的解决

dokuwiki默认是使用urlencode函数对文件名进行编码后存储的,而索引文章的indexer.php文件在生成sitemap.xml时也会对文件名编码,这样对搜索引擎是不友好的,实际上将这两个编码的功能去掉就可以了。 中文文件名的乱码可以参考http://www.dokuwiki.org/zh:pagename进行更改,即: function utf8_encodeFN($file, $safe = true) { if ($safe && preg_match(’#^[a-zA-Z0-9/_\-.%]+$#’, $file)) { return $file; } /* 把这个部分注释掉 $file = urlencode($file); $file = str_replace(‘%2F’,'/’,$file); */ return $file; } } if (!function_exists(’utf8_decodeFN’)) { /** * URL-Decode a filename * * … Continue reading

Posted in PHP, 原创 | Tagged , , , | Leave a comment

QString, wchar_t *, TCHAR, CString和其他字符或字符串类型的转换

这篇文章是在Blogspot上看到的一篇文章,能够解决QString, wchar_t *, TCHAR和其他字符或字符串类型之间的转换,方便在使用Windows API的时候转换的麻烦。 原文地址:http://tkrotoff.blogspot.com/2010/04/code-snippets-about-qstring-wchart.html //QString to wchar_t *: const wchar_t * encodedName = reinterpret_cast<const wchar_t *>(fileName.utf16()); //QString to char * given a file name: QByteArray fileName = QFile::encodeName(aFileName); const char * encodedName = fileName.constData(); //Valid as long as … Continue reading

Posted in Qt, 转载 | Tagged , , , | Leave a comment

Qt中addStretch的有趣应用

今天在使用addStretch,布局的时候,发现addStretch竟然是可以平均分配的,有意思。比如: QVBoxLayout *buttonLayout = new QVBoxLayout; buttonLayout->addStretch(1); buttonLayout->addWidget(Button1); buttonLayout->addStretch(1); buttonLayout->addWidget(Button2); buttonLayout->addStretch(1); buttonLayout->addWidget(Button3); buttonLayout->addStretch(6); 您会发现,buttonLayout的布局将空白没有widget的地方分成了9份,然后按照您所规定的地方分配弹簧,于是布局起来就方便多了,以前没有发现这个,一直还为布局头疼呢,现在有点门路了。

Posted in Qt, 原创 | Tagged , | Leave a comment