Using QProcess with mdb-tools



  • I understand this isn't an mdb-tools forum (although, there is no forum denoted towards the linux software mdb-tools unfortunately).

    I have posted before about trying to convert a .mdb file into a csv file or trying to access a .mdb file via database commands. What I have resulted in doing is using a QProcess that uses mdb-tables, mdb-export, all apart of mdb-tools to convert my .mdb file on a table basis.

    here is the code for how I run the QProcess:

    @
    QProcess gettables;
    QString tbl_cmd = "mdb-tables -d, '";
    QString cmd;

    // generate arguments
    cmd = tbl_cmd.append(filename);
    cmd = cmd.append("'");
    
    // get table names
    gettables.start(cmd);    // start cmd
    gettables.waitForFinished(-1);          // wait till done...
    QString output = gettables.readAllStandardOutput();     // get std output
    QString strerror = gettables.readAllStandardError();    // get std output errors
    qDebug() << output;     // print output
    qDebug() << strerror;   // print errors
    

    @

    where filename is a variable that gets set from a dialog box that the user selected the file name.

    If I simply type in the terminal window outside of my Qt App:
    mdb-tables -d, 'file name'

    The output is successful and it displays the tables in a comma delimited format.

    Now, when I try to run my QProcess through my Qt code, I get the following error:
    "Can't alloc filename, Couldn't open database" which is flagged by the std_error debug statement.

    I guess I am trying to figure out if I am using QProcess correctly or if its an mdb-tools issue. For some reason I feel like I am since I tried a simple printf statement saying hello world and the qDebug() printed out the std out statement correctly.

    Anyone have any thoughts?



  • Yes. Pass each and every argument to QProcess as a separate string in the arguments stringlist.

    So, that is, change your code to this:
    @
    QProcess gettables;
    QString cmd = "mdb-tables";
    QStringList argss;
    args << "-d"; //removed the comma that was there in your original code, did it really belong there?
    args << filename;

    // get table names
    gettables.start(cmd, args); // start cmd
    gettables.waitForFinished(-1); // wait till done...
    QString output = gettables.readAllStandardOutput(); // get std output
    QString strerror = gettables.readAllStandardError(); // get std output errors
    qDebug() << output; // print output
    qDebug() << strerror; // print errors
    @

    Futhermore, considder if you can switch to the asynchronic API instead of using waitForFinished.



  • Unfortunately, I had tried that previously using the arguments and and the command. So it seems it doesn't like something within the process initialization or something of that sort because I used your exact code and I get the same error. I just find it weird that I can use the same exact command on the command line and get an output, yet when I try to use it through a QProcess, it flags an error.

    Back to the drawing board!

    p.s. the comma is supposed to be there, -d is the delimiter flag, and the "," is the separator. My goal was to get the table names in a list and create the csv files accordingly using the split function. :P


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.