LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Passing command-line arguments to qglviewer application (http://www.linuxquestions.org/questions/programming-9/passing-command-line-arguments-to-qglviewer-application-739886/)

MALDATA 07-13-2009 10:23 PM

Passing command-line arguments to qglviewer application
 
I am learning how to use QGLviewer and I'm having a little trouble with a fairly simple concept. I want to give my program a file name as a command line argument. All of the sample programs I find have a main.cpp file like this:

Quote:

#include <QApplication>
#include "window.h"

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Window window;
window.show();
return app.exec();
}
Then the Window class, which is derived from QGLViewer, does all the program's actual work. If I want access to argc and argv, for example, to open and read a file that's passed as an argument, what would handle that? Is there a built-in way to get the arg variables to the window class, or do I need to just write a loadfile function and pass them? That seems a little clumsy to me, I feel like there's a better way, since this seems like a common task.

Any ideas?

Thanks!

paulsm4 07-15-2009 09:27 AM

Here's another (crude, but effective) way:
Code:

#include <QApplication>
#include "window.h"


// Declare these variables "extern" in the module that needs argc/argv
int g_argc;
char **g_argv;


int main(int argc, char *argv[])
{
  QApplication app(argc, argv);
  g_argc = argc;
  g_argv = argv;

  Window window;
  window.show();
  return app.exec();
}



All times are GMT -5. The time now is 11:17 AM.