0

I'm having trouble with using non-member functions in Qt. For example, here is the lines in my mainwindow.h generated from Qt creator template:

QT_BEGIN_NAMESPACE


namespace Ui {
class MainWindow;

void print_something_v2() {
    qInfo() << "I'm out of the main window!" << "\n";
}

}
QT_END_NAMESPACE


then I get the compiler error multiple definition of Ui::print_something_v2(); but things would work fine if I put the function as a member function of any class. Does Qt forbid using non-member functions? This is causing trouble for me when I'm trying to import some other libraries that are not written for Qt because they always contain some non-member functions.

DiveIntoML
  • 2,347
  • 2
  • 20
  • 36
  • 1
    You probably want to define your function inline, or move the definition to a separate cpp file. This is not related to Qt. – m7913d Sep 27 '22 at 20:16
  • 1
    thanks guys, you are right that this has nothing to do with Qt and is indeed answered in the link. My previous code works accidentally because it only has a single .cpp file, so this multiple definition is avoided by luck. – DiveIntoML Sep 27 '22 at 20:43

0 Answers0