Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt custom library in non Qt application
Forum Updated to NodeBB v4.3 + New Features

Qt custom library in non Qt application

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 729 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    luca
    wrote on last edited by
    #1

    Hi all,
    I'm trying to develop a c++ library using Qt to be used in non Qt c++ applications without success.
    The main problem seems to be how to start the event loop in the Qt Library.

    My library has the following source code:

    engine.cpp

    #include "engine.h"
    
    #include <QDebug>
    
    int Engine::argc = 1;
    char  *Engine::argv[] = {"Untitled", NULL};
    QCoreApplication * Engine::app=NULL;
    QThread * Engine::thread = NULL;
    
    
    Engine::Engine(QObject *parent) : QObject(parent)
    {
        if (thread == NULL)
        {
            thread = new QThread();
            connect(thread, SIGNAL(started()), this, SLOT(onStarted()), Qt::DirectConnection);
            thread->start();
        }
    }
    void Engine::onStarted()
    {
       if (QCoreApplication::instance() == NULL)
       {
           app = new QCoreApplication(argc, argv);
           app->exec();
       }
    //    startTimer(1000);
    }
    void Engine::timerEvent(QTimerEvent *e)
    {
        qDebug() << "Engine::timerEvent";
    }
    
    

    untitled.cpp

    #include "untitled.h"
    #include <QDebug>
    #include "engine.h"
    Untitled::Untitled()
    {
        e = new Engine();
    }
    

    and in the application that link to the library I have:

    #include <iostream>
    #include <unistd.h>
    #include "untitled.h"
    using namespace std;
    int main()
    {
        Untitled *u = new Untitled();
        while (1) {
            usleep(1000000);
            cout << "Hello World!" << endl;
        }
        return 0;
    }
    

    When running the application I get:

    QApplication was not created in the main() thread.
    

    Is there a solution?

    Thanks

    Luca

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved