January 16, 2012

wonopon12 wonopon12
Lab Rat
13 posts

A few questions on Qt

 

Hey everyone, I had a few questions I was wondering if anyone could answer :D Thanks for your help guys!

1) How can you open a text document with Notepad? (I don’t mean with QFile or QTextStream)

2) How can you open a new window from pressing a button on your QMainWindow? (I want to open a About the program window by pressing a button on my QMainWindow)

3) How do you make QFileDialog only work with files?

3 replies

January 16, 2012

sierdzio sierdzio
Area 51 Engineer
2536 posts

Ad. 1. Certainly no cross-platform way of doing that. I don’t use Windows, but I guess it would involve running something like “notepad fileToOpen.txt” in the terminal (console). In Qt, you can do that with QProcess.

Ad. 2. Connect button’s clicked() signal to a slot of your choice. In the slot, run:

  1. QMessageBox::aboutQt(parent, title);

This can also be done in many other ways.

Ad. 3. What do you mean by “work with files”? You mean you want to display only files? That would be strange. Anyway, what you probably need is to look into static members of QFileDialog (::getOpenFileName(), ::getOpenFileNames() etc.), or/ and the QFileDialog::FileMode flag.

 Signature 

(Z(:^

January 16, 2012

wonopon12 wonopon12
Lab Rat
13 posts

Thanks for your reply. For the 2nd question, I meant with a already created *.ui file, not with a QMessageBox. Thanks!

January 17, 2012

sierdzio sierdzio
Area 51 Engineer
2536 posts

The procedure is very similar. You have to include the UI header, initialise the object somewhere in your code (e.g. in main window’s constructor. This, again, can be done in many ways). Next, connect button’s signal to your slot, and there call:

  1. myNewWindow->show();

 Signature 

(Z(:^

 
  ‹‹ How to pause Visual studio debugger on Q_ASSERT fail.      Getting the error "ERROR: Symbol file could not be found." when Debugging ››

You must log in to post a reply. Not a member yet? Register here!