Building argv and argc
        Posted  
        
            by 
                Wylie Coyote SG.
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Wylie Coyote SG.
        
        
        
        Published on 2012-04-06T23:25:36Z
        Indexed on 
            2012/04/06
            23:29 UTC
        
        
        Read the original article
        Hit count: 241
        
I'm a student programmer using Qt to build a GUI application for work. The primary purpose of this application is to open some of our old style files, allows better editing and then save the file in a new format and file extension. Recently I have been asked to allow this conversion to take place from a terminal. While I do know what argv and argc are along with what they represent I am unsure how to accomplish what they want. For instance how to handle relative paths vs. absolute... maybe how to get absolute from relative; perhaps none of that is even needed. My programming experience has been primarily with guis so this is a little new to me.
Users would like the following to be ran from the terminal
application -o /fileLocation /fileDestination template(to determine new format)
I began to use for loops and if statements to begin accomplishing this when I relized that I might be taking the worng approach to all of this. I WOULD ALSO BE REALLY INTERESTED IF QT HAS SOMETHING FOR THIS! Here is what I have began coming up with:
int main(int argc, char *argv[])
{
    if(argc > 1)
    {
        for(int i = 0; i < argc; i++)
        {
            if(argv[i] == "-c")
            {
                QString fileName = QString::fromStdString(argv[i+1]);
                QString fileDestination = QString::fromStdString(argv[i+2]);
                QString templateName = QString::fromStdString(argv[i+3]);
                QFile fileToConvert(fileName);
                if(fileToConvert.open(QFile::ReadOnly))
                {
                //do stuff
Thanks for reading my post and a big thanks for any contributions you make to helping me overcome this issue.
© Stack Overflow or respective owner