我想在PlainTextEdit控件顯示ASCII字符,但我碰到的在我的線一半突然停電的問題。有一個\ n字符,我實際上希望文本開始一個新行,所以這個字換行功能是不可取的。我已經嘗試將換行和換行模式設置爲NoWrap,但它仍會產生下面顯示的相同的不受歡迎的圖像。由於專有原因,我無法顯示所有文本,但實質上會發生什麼,每個C應該是新行的開始。每行有80個字符,因此循環。該部件比文本包裝的位置大得多,所以我不確定這裏發生了什麼。QPlainTextEdit換行裹當設置爲不換行
uint8_t count = 0;
QString textualFileCharacterString;
char currentCharacter;
const char* currentCharacterPointer = ¤tCharacter;
while (bytePosition < 3200)
{
for(count = 0; count < 80; count ++)
{
file.seekg(bytePosition);
file.read((char*)(&ASCIIorEBCDICchar[0]), BUF_LEN_1);
if (EBCDICtoASCIIConvNeeded == TRUE)
currentCharacter = ebc_to_ascii_table(ASCIIorEBCDICchar[0]); // file is encoded in EBCDIC
else
currentCharacter = ASCIIorEBCDICchar[0]; // file is encoded in ASCII
// if(currentCharacter == 32)//Auto space formatting fix, if current character equals space it converts it to a dot
// currentCharacter = 46;
textualFileCharacterString = QString::fromUtf8(currentCharacterPointer, ONE_BYTE); //converts ASCII value to usable QString
ui->TextualFileHeaderPlainTextEdit->insertPlainText(textualFileCharacterString);
count++;
bytePosition++;
}
ui->TextualFileHeaderPlainTextEdit->insertPlainText("\n");
}
ui->TextualFileHeaderPlainTextEdit->setReadOnly(true);
ui->TextualFileHeaderPlainTextEdit->setLineWrapMode(QPlainTextEdit::NoWrap);
ui->TextualFileHeaderPlainTextEdit->setWordWrapMode(QTextOption::NoWrap);
編輯: 我試圖環路
QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
QTextCodec::ConverterState converterState(QTextCodec::DefaultConversion);
QTextCodec::ConverterState* converterStatePointer = &converterState;
而且這些行的代碼之前加入這些代碼行,第一個所述ASCII轉換爲一個字節數組,而第二個將字節數組轉換爲字符串(從另一個Stack頁面獲取)。
QByteArray byteArray = QTextCodec::convertFromUnicode(currentCharacterPointer, ONE_BYTE, converterStatePointer); //0 indicates the conversion is stateless
textualFileCharacterString = QTextCodec::codecForMib(1015)->toUnicode(byteArray);
我得到第二行的警告,雖然聲稱沒有匹配函數的調用...
convertFromUnicode(const char*&, int, QTextCodec::ConverterState*&);
或'QTextCodec來:: setCodecForLocale(QTextCodec來:: codecForName( 「UTF-8」));' –
fromAscii()中的溶液中除去5不幸 – CrippledTable
然後使用'QTextCodec來:: setCodecForLocale(QTextCodec來:: codecForName(」 UTF-8" ));' –