QXlsx icon indicating copy to clipboard operation
QXlsx copied to clipboard

load .so and unload it without instance Qxlsx::document may crash

Open tacochun opened this issue 4 years ago โ€ข 8 comments

Hi , i am sorry for my poor english and coding skill first , but i have tried my best and still can't figure it out , I appreciate any help

In my main code , i will test every(3) case with

  1. load .so
  2. resolve
  3. unload

every case include "xlsxdocument.h" but if the first case is do without instance ( Qxlsx::document ), it will crash at the second times Qxlsx::document

Some results i tried, called do nothing case = N, called do Qxlsx::document case = A & B, it will crash by

  1. N -> A -> B(crash in d_ptr->loadPackage(&xlsx))

it wont crash by

  1. N -> A -> A
  2. A ->
  3. N ( without include"xlsxdocument.h") ->
  4. without unload

is it something i did wrong or it's a bug ? thanks (Qt5.9.1 Ubuntu16.04.3)

tacochun avatar Mar 31 '21 11:03 tacochun

Dear @tacochun My English is not good either. ๐Ÿ’

Can you show us your example code?

And... In my opinion, the version of Qt doesn't seem to be an issue. Maybe.

j2doll avatar Apr 03 '21 10:04 j2doll

Dear @j2doll I think these simple example can reproduce the problem.I hope it will be helpful to you

//Ntest.h

#ifndef Ntest_H
#define Ntest_H
#include "Ntest_global.h"
#include <QThread>

class NTESTSHARED_EXPORT Ntest: public QThread
{
    Q_OBJECT
public:
    Ntest();
    ~Ntest();
};
extern "C" NTESTSHARED_EXPORT QThread *GetTest()
{
   return new Ntest();
}
#endif 
//Ntest.cpp

#include "Ntest.h"
#include "xlsxdocument.h"
Ntest::Ntest()
{
    //A & B test will do the instance below
    //Qxlsx::Document xlsx("/RealPath") 
}
Ntest::~Ntest()
{
}

in my MainWindow will do the API to these library

bool MainWindow::LoadTest(QString libFileName)
{
    // in .h
    // typedef QThread* (*GetTest)();
    // QLibrary lib;

    GetTest getTestFunction;
   
    libFileName = "/tmp/" + libFileName;
    if(QFile(libFileName).exists())
    {
        lib.setFileName(libFileName);
        lib.load();
    }
    else
    {
        return false;
    }

    if(!lib.isLoaded())
    {
        return false;
    }

    getTestFunction= (GetTest)lib.resolve("GetTest");
    if(!getTestFunction)
    {
        return false;
    }
    getTestFunction();
    lib.unload();
    return true;
}

tacochun avatar Apr 07 '21 08:04 tacochun

Sorry for the late reply. I created a repository for testing. https://github.com/JayTwoLab/qxlsx-issues-151 Can you make a pull request for testing?

j2doll avatar Apr 15 '21 12:04 j2doll

I also encountered a similar problem in my UI tool. It crashed when calling QXlsx::Document to create an object, but the probability of recurrence was low, the last position of the crash is "Styles::readFont()-> format.setProperty(FormatPrivate::P_Font_Color, color)->XlsxColor::operator QVariant() const->return QVariant(cref, this);".

happyweiwei avatar May 07 '21 14:05 happyweiwei

Because of the following code, it does not work in the dll(so) project.

########################################
# source code 

HEADERS += $$files($${QXLSX_HEADERPATH}*.h)
SOURCES += $$files($${QXLSX_SOURCEPATH}*.cpp)

There is a difference between version 1.4.0 and the current version. I am going to supplement that code.

Thanks for reporting. ๐Ÿ‘

j2doll avatar May 07 '21 14:05 j2doll

Because of the following code, it does not work in the dll(so) project.

########################################
# source code 

HEADERS += $$files($${QXLSX_HEADERPATH}*.h)
SOURCES += $$files($${QXLSX_SOURCEPATH}*.cpp)

There is a difference between version 1.4.0 and the current version. I am going to supplement that code.

Thanks for reporting. ๐Ÿ‘

Thanks for your update. The similar issue in my UI tool may have been solved by updating QXlsx.pri file.
And could you please tell me why this modification can help solve the issue๏ผŒor if any document can helpful for this. Thanks a lot!

happyweiwei avatar May 07 '21 17:05 happyweiwei

Dear @j2doll I think the problem is still remain in my UI tool, I will put all my .so to a folder, Could this be the reason ?

tacochun avatar May 10 '21 14:05 tacochun

Dear @j2doll I think the problem is still remain in my UI tool, I will put all my .so to a folder, Could this be the reason ?

Pull request to https://github.com/JayTwoLab/qxlsx-issues-151-2.git

j2doll avatar May 16 '21 11:05 j2doll