简体   繁体   中英

Contents of Text File into QMessageBox

I have what seems like a simple task, but I'm going crazy trying to figure this out.

I'm trying to write a C++ QT program. All I need to do is have some information displayed in a QMessageBox. I have a text file in the same directory as my program which contains several rows and columns of information that I would like to display in a QMessageBox.

I want the information displayed in the QMessageBox to be basically identical to how the file looks if I open it up in a text editor.

How would I go about doing this?

Your question lacks clarity. QMessageBox is used to display short messages like error messages, warnings, confirmation messages etc. It has 4 basic components - Title, Message Text, Icon, and set of buttons. So basically, there is no option to add something like a text editor within the QMessageBox. What is possible is to add text to the message, but it is designed to show only little text.

For just displaying the contents of a file, you can do something like

QMessageBox *msgbox = new QMessageBox;
QFile *file = new QFile ("text.txt");
if (file->open (QIODevice::ReadOnly) == true)
{
    msgbox->setText (QString (file->readAll ()));
    file->close ();
}
msgbox->exec ();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM