Czech

Gt 4.1

Qt 4.1 Knowledge


06.08.25

UTF-8 encoding

In linux I have set UTF-8 encoding and all work without problems. But in windows it still show scattered tea. Finally i found a simple function.

QTextStream kIn(&kFile);
kIn.setCodec("UTF-8");

This function is calling over saving or loading files with UTF-8 strings.

Next function also translate string to the UTF-8 encoding.

QString str = "Háčky, čárky";
// Translate string to UTF8 encoding
str = QApplication::translate("CMainWindow", str.toStdString().c_str(), 0, QApplication::UnicodeUTF8);


Layouts

In the following way we add to the dialog some widgets, which automatically resize by dialog size.

QLabel *m_pLabelApp;
QTextBrowser *m_pTextBrowser;
QWidget *m_pHorizontalLayout;
QHBoxLayout *m_pHBoxLayout;

m_pLabelApp = new QLabel(QDialog);
m_pTextBrowser = new QTextBrowser(QDialog);
m_pHorizontalLayout = new QWidget(QDialog);
m_pHBoxLayout = new QHBoxLayout(m_pHorizontalLayout);

QVBoxLayout *pMainLayout = new QVBoxLayout;
pMainLayout->addWidget(m_pLabelApp);
pMainLayout->addWidget(m_pTextBrowser);
m_pHorizontalLayout->setLayout(m_pHBoxLayout);
pMainLayout->addWidget(m_pHorizontalLayout);
setLayout(pMainLayout);>


home / qt


Valid XHTML 1.0 Transitional