Help answer threads with 0 replies.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 07-13-2009, 10:23 PM   #1
Registered: Mar 2005
Posts: 114

Rep: Reputation: 17
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:

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

int main(int argc, char *argv[])
QApplication app(argc, argv);
Window window;;
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?

Old 07-15-2009, 09:27 AM   #2
LQ Guru
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Here's another (crude, but effective) way:
#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;;
  return app.exec();

Last edited by paulsm4; 07-15-2009 at 09:29 AM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing command line arguments through getopts and long options neville310 Programming 3 04-16-2007 06:38 AM
command line arguments containing ( Lotharster Linux - Newbie 3 01-05-2006 08:43 AM
Passing a text file to the command line as arguments wimnat Linux - General 2 12-05-2005 08:09 AM
passing a list of arguments to a command hdagelic Linux - General 2 05-09-2005 09:30 AM
Help with command line arguments ? synapse Linux - Newbie 2 02-23-2004 02:25 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:32 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration