Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED]Qmessagebox is causing windows explorer to open the application directory
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]Qmessagebox is causing windows explorer to open the application directory

Scheduled Pinned Locked Moved General and Desktop
15 Posts 3 Posters 3.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • JeroentjehomeJ Offline
    JeroentjehomeJ Offline
    Jeroentjehome
    wrote on last edited by
    #4

    oke, you can leave out the this pointer. It will not have a parent. Not a problem. The dialog is set to modal as default!
    And I conclude that your code is placed outside a QObject class then?

    Greetz, Jeroen

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #5

      Hi,

      Having the complete function could be useful

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • V Offline
        V Offline
        Valueduser
        wrote on last edited by
        #6

        Correct, this code is coming from a function, I've written. How do I go about leaving out the pointer? Thanks in advance for the help, its been many years since I've done any object oriented programming and this is my first time using Qt.

        1 Reply Last reply
        0
        • JeroentjehomeJ Offline
          JeroentjehomeJ Offline
          Jeroentjehome
          wrote on last edited by
          #7

          NULL or 0, that should do the trick! Like SGalst says, seeing all the function we could help more!
          Gr

          Greetz, Jeroen

          1 Reply Last reply
          0
          • V Offline
            V Offline
            Valueduser
            wrote on last edited by
            #8

            Complete Function:
            @void FileWrite (QString Filename,QString R1,QString R2,QString R3,QString R4,QString R5,int pos,QString event,QString fs,QString elsize) //function used to write files
            {
            //QMessageBox msgBox; //create a message box object to alert the user that an output filename must be specified
            // msgBox.setText("Please specify output file using the Save As button"); //set text of the message box

            //create a series of Qfile objects that read in the resource files
            QFile mFile_1(R1);
            if(!mFile_1.open(QFile::ReadOnly | QFile::Text))
            {
                qDebug()<<"Could not open file for read";
                return;
            }
            QTextStream in1(&mFile_1);
            QString rt1 = in1.readAll();
            
            QFile mFile_2(R2);
            if(!mFile_2.open(QFile::ReadOnly | QFile::Text))
            {
                qDebug()<<"Could not open file for read";
                return;
            }
            QTextStream in2(&mFile_2);
            QString rt2 = in2.readAll();
            
            QFile mFile_3(R3);
            if(!mFile_3.open(QFile::ReadOnly | QFile::Text))
            {
                qDebug()<<"Could not open file for read";
                return;
            }
            QTextStream in3(&mFile_3);
            QString rt3 = in3.readAll();
            
            QFile mFile_4(R4);
            if(!mFile_4.open(QFile::ReadOnly | QFile::Text))
            {
                qDebug()<<"Could not open file for read";
                return;
            }
            QTextStream in4(&mFile_4);
            QString rt4 = in4.readAll();
            
            QFile mFile_5(R5);
            if(!mFile_5.open(QFile::ReadOnly | QFile::Text))
            {
                qDebug()<<"Could not open file for read";
                return;
            }
            QTextStream in5(&mFile_5);
            QString rt5 = in5.readAll();
            
            //open output file
            QFile mFile&#40;Filename&#41;;
            
            if(!mFile.open(QFile::WriteOnly | QFile::Text))
            {
               QMessageBox::warning(,"You idiot", "Select a proper file!!");
              //  msgBox.exec&#40;&#41;; //if file output was not specified alert user with message box
                //qDebug()<<"Could not open file";
                return;
            }
            QTextStream out(&mFile); //create a text stream output to the output file
            

            // qDebug()<<fs;
            out<<rt1<<pos<<rt2<<event<<rt3<<fs<<rt4<<elsize<<rt5; //concatenate user input with resource files to output

            mFile.flush();
            mFile.close();
            

            }@

            1 Reply Last reply
            0
            • V Offline
              V Offline
              Valueduser
              wrote on last edited by
              #9

              Using Null got it to work, however, my original problem persists, after clicking ok in the message box, windows explorer pops open the program directory

              1 Reply Last reply
              0
              • JeroentjehomeJ Offline
                JeroentjehomeJ Offline
                Jeroentjehome
                wrote on last edited by
                #10

                Yup, It might be your QFile use.
                Do try this:
                @
                QFile File_f(FileName_str);
                if (File_f.exists() == true)
                {
                // store your data
                }
                else
                {
                // Give warning, no such file
                QMEssageBox::warning(0, "Idiot", "That is not a good spot, try another!!");
                }
                @

                Greetz, Jeroen

                1 Reply Last reply
                0
                • JeroentjehomeJ Offline
                  JeroentjehomeJ Offline
                  Jeroentjehome
                  wrote on last edited by
                  #11

                  Ah, might found the problem:
                  @
                  File_f.open(QIODevice::WriteOnly | QIODevice::Text);
                  @

                  Greetz, Jeroen

                  1 Reply Last reply
                  0
                  • V Offline
                    V Offline
                    Valueduser
                    wrote on last edited by
                    #12

                    It's still not working. Thank you all for the help, I'm going to go a bit deeper with the debugger and read up on some more of the documentation to see if I can figure out whats going on.

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #13

                      On a side note, why allow your user to give an improper file name ? You can use QFileDialog::getSaveFileName() to unsure that you have a something that is correct in the first place

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • V Offline
                        V Offline
                        Valueduser
                        wrote on last edited by
                        #14

                        [quote author="SGaist" date="1386192093"]On a side note, why allow your user to give an improper file name ? You can use QFileDialog::getSaveFileName() to unsure that you have a something that is correct in the first place[/quote]

                        It's not that they're giving an improper file name, it's only if there hasn't been one specified at all.

                        I figured out what was causing the problem, it had nothing to do with the message box. After the filewrite function executed I used QDesktopsrvices to open a url (which is the file being written. In the case where a file wasn't written it was defaulting to opening windows explorer.
                        I solved the problem by adding conditional control to the desktopservices call, and making my filewrite function return a bool indicating whether or not a file was actually written.

                        Once again thank you all for the help and guidance, it is greatly appreciated

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #15

                          You're welcome !

                          Then I would recommend to end the function early e.g. first check to make so you don't do all the processing in vain.

                          Since you have it working now, please update the thread title prepending [solved] so other forum users may know a solution has been found :)

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply
                          0

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved