0

Hey so I need to export a qt application as a .dll and , so I dont want any arguments like argc and argv , but QApplication needs them , so i tried this

int main()
{
    int c=1;
    char** v = (char**)("ApplicationName");
    QApplication app(c,v);
    MainWindow window;
    window.show();
    return app.exec();
}

but I get segfault from QtCore... Can someone help me bypass the segfault and create the QApplication without needing argc and argv? This didnt solve the problem cause it needs argv defined ... QApplication app(argc, argv)

wohlstad
  • 12,661
  • 10
  • 26
  • 39
  • 1
    By convention, `argv` should start with the name of the program (at position 0). – lorro Aug 14 '22 at 16:27
  • How could that work for a .dll? – S.T.A.L.K.E.R Aug 14 '22 at 16:28
  • 1
    `char** v` should be `char* v[]`, i.e. `v` should point a pointer, but you forced it to point a char. – 273K Aug 14 '22 at 16:28
  • @273K can you provide the whole expression? like how the cast should work? is it like this int c=1; char* []v = (char*[])("ApplicationName"); QApplication app(c,v);? – S.T.A.L.K.E.R Aug 14 '22 at 16:30
  • 1
    `const char* v[] = { "ApplicationName" };` Use the type cast later. – 273K Aug 14 '22 at 16:31
  • Thanks that fixed it! `int c=1; char* v[] = {(char*)"ApplicationName"}; QApplication app(c,v);` – S.T.A.L.K.E.R Aug 14 '22 at 16:34
  • Avoid C-style casts. They have too many possible meanings which is the issue here: You're basically `reinterpret_cast`ing from `char const*` to `char**`. Use `char* argv[1] { const_cast("ApplicationName")};` instead. – fabian Aug 14 '22 at 16:38

1 Answers1

0

Try this:

int main()
{
    char* args[] = { (char*)"AppName" };
    QApplication app(1,args);
    MainWindow window;
    window.show();
    return app.exec();
}
Something Something
  • 3,999
  • 1
  • 6
  • 21