Hi everyone, I am working on a 3D viewer using libQGLViewer. In all of the examples provided, the main function looks something like this:

int main(int argc, char** argv){
  QApplication application(argc, argv);
  Viewer viewer;
#if QT_VERSION < 0x040000
  application.setMainWidget(&viewer);
#else
  viewer.setWindowTitle("pointCloud");
#endif
  viewer.show();

  return(g_qApplication.exec()); //waits for Esc
}

The application and viewer objects need only be referenced in the main loop for all of the examples provided, but for my program, I need to call a function viewer.updateGL() that exists outside the main loop. So I made viewer global. This was not OK, QApplication complained because it needs to be constructed before the Viewer. So I made QApplication application(argc, argv); global with both arguments NULL because I don't use them. QT complained and said it needs real arguments, specifically, the first argument cannot be zero and the second must contain atleast one argument. Problem is, I have no idea how to set a string in a double pointer char (ie. char **argv). I just wasted a lot of time trying to find out and didn't come up with anything. Anyone have any ideas? I basically want this: argv[0] = "./PointCloud", where argv[0][0] to argv[0][12] would contain all the letters and a NULL terminator at the end. There has to be a simple way to do this. Thanks.

Read this and do the one appropriate for Win or *nix, depending on what you're coding for.

http://doc.qt.nokia.com/latest/qcoreapplication.html#arguments

The arguments are taken from the arguments you pass to the main function when you start the programme. What command line arguments are you passing in to main?

If used, the arguments to main() are always going to be at least argc = 1 and argv[0] = "[I]executableName[/I]" . As you add more command line arguments, argc will increase and argv will get more elements.

I find that it tends to help if you draw parallels between main() and user-defined functions. Try to think of argv as an array of values and argc as an "arraySize" variable. To be able to use an array (argv) effectively as an argument/parameter, you need to know the size (argc).

Thus, in this case, if you want to be able to use "./PointCloud" as your program name, that is the value that will be stored in argv[0] automatically. Any command-line switches/arguments will be stored in argv[1] or later.

I don't know much about libQGLViewer, but you could try keeping viewer local and just making a variable that points to viewer global, and call updateGL using that pointer.

I know how the command line arguments work. That is not my question. I have to make the line

QApplication application(argc, argv);

global. In order to do so I have to make two arguments. As stated in my original post, I do not know how I can set a string to a double char pointer.

chrjs,
So I already tried that. That was actually one of the first things I thought of. So as I was typing this response to you, on a hunch, I decided to try it again. I made a global Viewer *view, then set that equal to &viewer in main(), then in my function call I used (*view).updateGL(); and I was getting an error when I executed the function. Well the function was this:

void on_trackbar(int h){
    (*view).updateGL();
}

on_trackbar(int h) is an openCV function that is called whenever the trackbar is moved. Turns out when I initialize the trackbar (which was in main(), before the view = &viewer) OpenCV calls this on_trackbar() function. So that's where the problem was. The (*view).updateGL() function was being called in on_trackbar() without me knowing. So I put view = &viewer; before the trackbar initialization and everything worked. Thanks, without your post I would have never tried that again.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.