Ok first off I am a total noob at C++ and QT as I just started a few days ago, but I have been trudging through some online tutorials and just recently hit a snag. I am quite sure it's a simple issue, but here goes.

Got a list widget, line edit widget and a button that when pressed outputs the text to the list widget and then outputs to a file. Now I got it working great as long as I hard coded the filename into my program, but when I wanted to possibly create a new file I could not figure out where to put it.

You can see below where I wanted to put it, but I knew it would not work since it was encapsulated by the if statement. I think my brain is fried from looking at all this for too long hehe.

Qt Code:
  1. void DialogImpl::doSomething() {
  2. QString linedt = lineEdit->text(); // Set linedt to the text in the Line Edit box
  3. if (!file.isOpen()) && ( linedt != "" ) { // If file is not open then open it
  4. QFile file("/home/jingoism/" + linedt); // This is wrong, and the part I dont understand
  5. QTextStream out(&file); // Also wrong, should go with QFile
  6. file.open(QIODevice::WriteOnly | QIODevice::Text); // Open the file as Writeonly
  7. listWidget->addItem("Opened File!"); // Verify in listWidget file is opened
  8. listWidget->addItem(linedt); // Add the line of text to the listWidget
  9. out << linedt << endl; // Add the line to the file
  10. lineEdit->clear(); // Clear the LineEdit box
  11. } else {
  12. if ( linedt != "" ) { // If text in the Line Edit box is not null then proceed
  13. out << linedt << endl;
  14. listWidget->addItem(linedt);
  15. lineEdit->clear();
  16. }
  17. }
  18. }
To copy to clipboard, switch view to plain text mode