开发者

QTextBrowser's setSource crashing

I'm writing an application with Qt that uses QTextBrowser to display some locally-stored HTML. When using it at startup, it works fine, but I get strange errors after querying a database for the path to the HTML file.

Here's the code:

The site of the error is the call to setSource().

However, note that I don't believe it be to simply a database problem because the code fails even when loading a perfectly fine HTML file as a constant argument

void MainWindow::LessonSelection_itemPressedSlot(QListWidgetItem* ITEM)
{
    //selection pressed, run this slot
    qWarning("ITEM PRESSED");
    //display ITEM's name
    qWarning(ITEM->text().toAscii());
    //name of the HTML file
    QString name = ITEM->text();
    //get the HTML Lesson object
    HTML_Lesson lesson = DatabaseHelper::getLessonWithName(name);
    //print the HTML path
    qWarning("HTML PATH:" + lesson.getHTML_Path().toAscii());
    //load the HTML file
    loadHTMLFiles(lesson);
}
void MainWindow::loadHTMLFiles(HTML_Lesson& LESSON)
{
    //ERROR HERE
    HTMLPage->setSource(QUrl(LESSON.getHTML_Path()));
}

Fails, as does

void MainWindow::LessonSelection_itemPressedSlot(QListWidgetItem* ITEM)
{
    //selection pressed, run this slot
        qWarning("ITEM PRESSED");
    //display ITEM's name
    qWarning(ITEM->text().toAscii());
    //name of the HTML file
    QString name = ITEM->text();
    //get the HTML Lesson object
    HTML_Lesson lesson = DatabaseHelper::getLessonWithName(name);

    //load the HTML file
    loadHTMLFiles(lesson);
}
void MainWindow::loadHTMLFiles(HTML_Lesson& LESSON)
{
    //ERROR HERE
    HTMLPage->setSource(“telephone.html);
}

Calling setSource anywhere else in my program doesn't crash.

It can't be a matter of object construction, because I can send it an HTML file elsewhere in the program and have it work correctly. It also can't be the database, since it doesn't work with an absolute path either. It produces the same error even after commenting out all the code besides the call to the error-producing function. Is it an issue of not being able to call setSource after showing the main window? If that's the case, what would I use to display different HTML files throughout the program?

Please try and run the code with your own html file.

Here's the debugger output, if it helps:

sql.html
QFSFileEngine::open: No file name specified
ITEM PRESSED
ANITEM
*** glibc detected *** /home/thomas/codehelp-build-desktop/codehelp: invalid fastbin entry (free): 0x00000000007b1c30 ***
======= Backtrace: =========
/lib/libc.so.6(+0x774b6)[0x7ffff5c474b6]
/lib/libc.so.6(cfree+0x73)[0x7ffff5c4dc83]
/home/thomas/qtsdk-2010.05/qt/lib/libQtCore.so.4(_ZN10QByteArrayaSERKS_+0x32)[0x7ffff699d4b2]
/home/thomas/qtsdk-2010.05/qt/lib/libQtCore.so.4(+0x14a8c2)[0x7ffff6a598c2]
/home/thomas/qtsdk-2010.05/qt/lib/libQtCore.so.4(_ZNK4QUrl7isValidEv+0x35)[0x7ffff6a59b15]
/home/thomas/qtsdk-2010.05/qt/lib/libQtGui.so.4(+0x6dac8a)[0x7ffff74ccc8a]
/home/thomas/qtsdk-2010.05/qt/lib/libQtGui.so.4(_ZN12QTextBrowser9setSourceERK4QUrl+0x4f)[0x7ffff74cef3f]
/home/thomas/codehelp-build-desktop/codehelp[0x405261]
/home/thomas/codehelp-build-desktop/codehelp[0x4051a5]
/home/thomas/codehelp-build-desktop/codehelp[0x4067b9]
/home/thomas/qtsdk-2010.05/qt/lib/libQtCore.so.4(_ZN11QMetaObject8activateEP7QObjectPKS_iPPv+0x298)[0x7ffff6ab80f8]
/home/thomas/qtsdk-2010.05/qt/lib/libQtGui.so.4(_ZN11QListWidget11itemPressedEP15QListWidgetItem+0x2f)[0x7ffff75ea87f]
/home/thomas/qtsdk-2010.05/qt/lib/libQtGui.so.4(_ZN11QListWidget11qt_metacallEN11QMetaObject4CallEiPPv+0x218)[0x7ffff75eeff8]
/home/thomas/qtsdk-2010.05/qt/lib/libQtCore.so.4(_ZN11QMetaObject8activateEP7QObjectPKS_iPPv+0x298)[0x7ffff6ab80f8]
/home/thomas/qtsdk-2010.05/qt/lib/libQtGui.so.4(_ZN17QAbstractItemView7pressedERK11QModelIndex+0x22)[0x7ffff757ae32]
/home/thomas/qtsdk-2010.05/qt/lib/libQtGui.so.4(_ZN17QAbstractItemView15mousePressEventEP11QMouseEvent+0x4df)[0x7ffff75855af]
/home/thomas/qtsdk-2010.05/qt/lib/libQtGui.so.4(_ZN7QWidget5eventEP6QEvent+0x824)[0x7ffff7055e44]
/home/thomas/qtsdk-2010.05/qt/lib/libQtGui.so.4(_ZN6QFrame5eventEP6QEvent+0x2b)[0x7ffff745041b]
/home/thomas/qtsdk-2010.05/qt/lib/libQtGui.so.4(_ZN19QAbstractScrollArea13viewportEventEP6QEvent+0x17)[0x7ffff74dfb87]
/home/thomas/qtsdk-2010.05/qt/lib/libQtGui.so.4(_ZN17QAbstractItemView13viewportEventEP6QEvent+0x195)[0x7ffff7589c35]
/home/thomas/qtsdk-2010.05/qt/lib/libQtGui.so.4(+0x6efb68)[0x7ffff74e1b68]
/home/thomas/qtsdk-2010.05/qt/lib/libQtCore.so.4(_ZN23QCoreApplicationPrivate29sendThroughObjectEventFiltersEP7QObjectP6QEvent+0x7e)[0x7ffff6aa244e]
/home/thomas/qtsdk-2010.05/qt/lib/libQtGui.so.4(_ZN19QApplicationPrivate13notify_helperEP7QObjectP6QEvent+0x80)[0x7ffff6ff5d30]
/home/thomas/qtsdk-2010.05/qt/lib/libQtGui.so.4(_ZN12QApplication6notifyEP7QObjectP6QEvent+0x172e)[0x7ffff6ffde8e]
/home/thomas/qtsdk-2010.05/qt/lib/libQtCore.so.4(_ZN16QCoreApplication14notifyInternalEP7QObjectP6QEvent+0x84)[0x7ffff6aa20a4]
/home/thomas/qtsdk-2010.05/qt/lib/libQtGui.so.4(_ZN19QApplicationPrivate14sendMouseEventEP7QWidgetP11QMouseEventS1_S1_PS1_R8QPointerIS0_Eb+0x177)[0x7ffff6ff8f27]
/home/thomas/qtsdk-2010.05/qt/lib/libQtGui.so.4(+0x28b61d)[0x7ffff707d61d]
/home/thomas/qtsdk-2010.05/qt/lib/libQtGui.so.4(_ZN12QApplication15x11ProcessEventEP7_XEvent+0x1156)[0x7ffff707c866]
/home/thomas/qtsdk-2010.05/qt/lib/libQtGui.so.4(+0x2b5038)[0x7ffff70a7038]
/lib/libglib-2.0.so.0(g_main_context_dispatch+0x1f2)[0x7ffff5521342]
/lib/libglib-2.0.so.0(+0x442a8)[0x7ffff55252a8]
/lib/libglib-2.0.so.0(g_main_context_iteration+0x6c)[0x7ffff552545c]
/home/thomas/qtsdk-2010.05/qt/lib/libQtCore.so.4(_ZN20QEventDispatcherGlib13processEventsE6QFlagsIN10QEventLoop17ProcessEventsFlagEE+0x5c)[0x7ffff6acfbcc]
/home/thomas/qtsdk-2010.05/qt/lib/libQtGui.so.4(+0x2b4bcf)[0x7ffff70a6bcf]
/home/thomas/qtsdk-2010.05/qt/lib/libQtCore.so.4(_ZN10QEventLoop13processEventsE6QFlagsINS_17ProcessEventsFlagEE+0x35)[0x7ffff6aa13f5]
/home/thomas/qtsdk-2010.05/qt/lib/libQtCore.so.4(_ZN10QEventLoop4execE6QFlagsINS_17ProcessEventsFlagEE+0xa6)[0x7ffff6aa1646]
/home/thomas/qtsdk-2010.05/qt/lib/libQtCore.so.4(_ZN16QCoreApplication4execEv+0xb4)[0x7ffff6aa3484开发者_运维百科]
/home/thomas/codehelp-build-desktop/codehelp[0x403b85]
/lib/libc.so.6(__libc_start_main+0xfe)[0x7ffff5beed8e]
/home/thomas/codehelp-build-desktop/codehelp[0x403879]
======= Memory map: ========
00400000-00409000 r-xp 00000000 08:16 2763162 /home/thomas/codehelp-build-desktop/codehelp
00608000-00609000 r--p 00008000 08:16 2763162 /home/thomas/codehelp-build-desktop/codehelp
00609000-0060a000 rw-p 00009000 08:16 2763162 /home/thomas/codehelp-build-desktop/codehelp
0060a000-013f9000 rw-p 00000000 00:00 0 [heap]
7fffddc5a000-7fffddc5f000 r-xp 00000000 08:16 4066237 /usr/lib/libdatrie.so.1.0.3
7fffddc5f000-7fffdde5e000 ---p 00005000 08:16 4066237 /usr/lib/libdatrie.so.1.0.3
7fffdde5e000-7fffdde5f000 r--p 00004000 08:16 4066237 /usr/lib/libdatrie.so.1.0.3
7fffdde5f000-7fffdde60000 rw-p 00005000 08:16 4066237 /usr/lib/libdatrie.so.1.0.3
7fffdde60000-7fffdde68000 r-xp 00000000 08:16 4066920 /usr/lib/libthai.so.0.1.6
7fffdde68000-7fffde067000 ---p 00008000 08:16 4066920 /usr/lib/libthai.so.0.1.6
7fffde067000-7fffde068000 r--p 00007000 08:16 4066920 /usr/lib/libthai.so.0.1.6
7fffde068000-7fffde069000 rw-p 00008000 08:16 4066920 /usr/lib/libthai.so.0.1.6
7fffde086000-7fffde0d0000 r--p 00000000 08:16 4983728 /usr/share/fonts/truetype/ttf-dejavu/DejaVuSansMono-Bold.ttf
7fffde0d0000-7fffde0d9000 r--p 00000000 08:16 4983878 /usr/share/fonts/type1/gsfonts/s050000l.pfb
7fffde0d9000-7fffde45c000 r--p 00000000 08:16 4983771 /usr/share/fonts/truetype/unfonts/UnBatang.ttf
7fffde45c000-7fffde94d000 r--p 00000000 08:16 4983775 /usr/share/fonts/truetype/wqy/wqy-microhei.ttc
7fffde94d000-7fffde96a000 r--p 00000000 08:16 917578 /usr/share/fonts/truetype/msttcorefonts/Webdings.ttf
7fffde96a000-7fffde980000 r--p 00000000 08:16 4983699 /usr/share/fonts/truetype/thai/Sawasdee.ttf
7fffde980000-7fffde9cd000 r--p 00000000 08:16 4983658 /usr/share/fonts/truetype/freefont/FreeMono.ttf
7fffde9cd000-7fffde9f9000 r--p 00000000 08:16 4983670 /usr/share/fonts/truetype/openoffice/opens___.ttf
7fffde9f9000-7fffdea29000 r--p 00000000 08:16 4983739 /usr/share/fonts/truetype/ttf-indic-fonts-core/Pothana2000.ttf
7fffdea29000-7fffdea42000 r--p 00000000 08:16 4983733 /usr/share/fonts/truetype/ttf-indic-fonts-core/Kedage-n.ttf
7fffdea42000-7fffdeb7d000 r--p 00000000 08:16 4983666 /usr/share/fonts/truetype/freefont/FreeSerif.ttf
7fffdeb7d000-7fffdeb9a000 r--p 00000000 08:16 917558 /usr/share/fonts/truetype/msttcorefonts/Arial_Black.ttf
7fffdeb9a000-7fffdebeb000 r--p 00000000 08:16 4983731 /usr/share/fonts/truetype/ttf-dejavu/DejaVuSerif.ttf
7fffdebeb000-7fffdec3a000 r--p 00000000 08:16 4983729 /usr/share/fonts/truetype/ttf-dejavu/DejaVuSansMono.ttf
7fffdec3a000-7fffdec84000 r--p 00000000 08:16 917565 /usr/share/fonts/truetype/msttcorefonts/Courier_New.ttf
7fffdec84000-7fffdf277000 r--p 00000000 08:16 4983671 /usr/share/fonts/truetype/takao/TakaoPGothic.ttf
7fffdf277000-7fffdf2d5000 r--p 00000000 08:16 4983740 /usr/share/fonts/truetype/ttf-indic-fonts-core/Rachana_04.ttf
7fffdf2d5000-7fffdf2ef000 r--p 00000000 08:16 4983691 /usr/share/fonts/truetype/thai/Norasi.ttf
7fffdf2ef000-7fffdf316000 r--p 00000000 08:16 4983748 /usr/share/fonts/truetype/ttf-indic-fonts-core/utkal.ttf
7fffdf316000-7fffdf32b000 r--p 00000000 08:16 4983741 /usr/share/fonts/truetype/ttf-indic-fonts-core/Rekha.ttf
7fffdf32b000-7fffdf33d000 r--p 00000000 08:16 4983743 /usr/share/fonts/truetype/ttf-indic-fonts-core/gargi.ttf
7fffdf33d000-7fffdf34a000 r--p 00000000 08:16 4983749 /usr/share/fonts/truetype/ttf-kacst-one/KacstOne.ttf
7fffdf34a000-7fffdf3bb000 r--p 00000000 08:16 4983662 /usr/share/fonts/truetype/freefont/FreeSans.ttf
7fffdf3bb000-7fffdf40d000 r--p 00000000 08:16 4983736 /usr/share/fonts/truetype/ttf-indic-fonts-core/Meera_04.ttf
7fffdf40d000-7fffdf421000 r--p 00000000 08:16 4983746 /usr/share/fonts/truetype/ttf-indic-fonts-core/lohit_hi.ttf
7fffdf421000-7fffdf435000 r--p 00000000 08:16 4983745 /usr/share/fonts/truetype/ttf-indic-fonts-core/lohit_gu.ttf
7fffdf435000-7fffdf458000 r--p 00000000 08:16 4983744 /usr/share/fonts/truetype/ttf-indic-fonts-core/lohit_bn.ttf
7fffdf458000-7fffdf674000 r--p 00000000 08:16 4983773 /usr/share/fonts/truetype/unfonts/UnDotum.ttf
7fffdf674000-7fffdf6a2000 r--p 00000000 08:16 4983737 /usr/share/fonts/truetype/ttf-indic-fonts-core/MuktiNarrow.ttf
7fffdf6a2000-7fffdf6e3000 r--p 00000000 08:16 4983750 /usr/share/fonts/truetype/ttf-khmeros-core/KhmerOS.ttf
7fffdf6e3000-7fffdf6f9000 r--p 00000000 08:16 4983725 /usr/share/fonts/truetype/thai/Waree.ttf
7fffdf6f9000-7fffdf70d000 r--p 00000000 08:16 4983818 /usr/share/fonts/type1/gsfonts/n019003l.pfb
7fffdf70d000-7fffdf751000 r--p 00000000 08:16 917592 /usr/share/fonts/truetype/msttcorefonts/Arial.ttf
7fffdf751000-7fffdf774000 r--p 00000000 08:16 925046 /usr/share/fonts/truetype/msttcorefonts/Verdana.ttf
7fffdf774000-7fffdf803000 r--p 00000000 08:16 4983726 /usr/share/fonts/truetype/ttf-dejavu/DejaVuSans-Bold.ttf
7fffdf803000-7fffdf865000 r--p 00000000 08:16 4983768 /usr/share/fonts/truetype/ubuntu-font-family/Ubuntu-BI.ttf
7fffdf865000-7fffdf8c5000 rw-s 00000000 00:04 14778389 /SYSV00000000 (deleted)
7fffdf8c5000-7fffdf960000 r--p 00000000 08:16 4983727 /usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf
7fffdf960000-7fffdf9b7000 r-xp 00000000 08:16 3026932 /home/thomas/qtsdk-2010.05/qt/plugins/imageformats/libqtiff.so
7fffd
f9b7000-7fffdfbb6000 ---p 00057000 08:16 3026932 /home/thomas/qtsdk-2010.05/qt/plugins/imageformats/libqtiff.so
7fffdfbb6000-7fffdfbb9000 rw-p 00056000 08:16 3026932 /home/thomas/qtsdk-2010.05/qt/plugins/imageformats/libqtiff.so
7fffdfbb9000-7fffdfc17000 r-xp 00000000 08:16 3556753 /home/thomas/qtsdk-2010.05/qt/lib/libQtSvg.so.4.7.0
7fffdfc17000-7fffdfe16000 ---p 0005e000 08:16 3556753 /home/thomas/qtsdk-2010.05/qt/lib/libQtSvg.so.4.7.0
7fffdfe16000-7fffdfe19000 rw-p 0005d000 08:16 3556753 /home/thomas/qtsdk-2010.05/qt/lib/libQtSvg.so.4.7.0
7fffdfe19000-7fffdfe1e000 r-xp 00000000 08:16 3026930 /home/thomas/qtsdk-2010.05/qt/plugins/imageformats/libqsvg.so
7fffdfe1e000-7fffe001e000 ---p 00005000 08:16 3026930 /home/thomas/qtsdk-2010.05/qt/plugins/imageformats/libqsvg.so
7fffe001e000-7fffe001f000 rw-p 00005000 08:16 3026930 /home/thomas/qtsdk-2010.05/qt/plugins/imageformats/libqsvg.so
7fffe001f000-7fffe0076000 r-xp 00000000 08:16 3026929 /home/thomas/qtsdk-2010.05/qt/plugins/imageformats/libqmng.so
7fffe0076000-7fffe0276000 ---p 00057000 08:16 3026929 /home/thomas/qtsdk-2010.05/qt/plugins/imageformats/libqmng.so
7fffe0276000-7fffe027a000 rw-p 00057000 08:16 3026929 /home/thomas/qtsdk-2010.05/qt/plugins/imageformats/libqmng.so
7fffe027a000-7fffe02b4000 r-xp 00000000 08:16 3026928 /home/thomas/qtsdk-2010.05/qt/plugins/imageformats/libqjpeg.so
7fffe02b4000-7fffe04b4000 ---p 0003a000 08:16 3026928 /home/thomas/qtsdk-2010.05/qt/plugins/imageformats/libqjpeg.so
7fffe04b4000-7fffe04b5000 rw-p 0003a000 08:16 3026928 /home/thomas/qtsdk-2010.05/qt/plugins/imageformats/libqjpeg.so
7fffe04b5000-7fffe04bc000 r-xp 00000000 08:16 3026927 /home/thomas/qtsdk-2010.05/qt/plugins/imageformats/libqico.so
7fffe04bc000-7fffe06bb000 ---p 00007000 08:16 3026927 /home/thomas/qtsdk-2010.05/qt/plugins/imageformats/libqico.so
7fffe06bb000-7fffe06bc000 rw-p 00006000 08:16 3026927 /home/thomas/qtsdk-2010.05/qt/plugins/imageformats/libqico.so
7fffe06bc000-7fffe06c3000 r-xp 00000000 08:16 3026931 /home/thomas/qtsdk-2010.05/qt/plugins/imageformats/libqgif.so
7fffe06c3000-7fffe08c3000 ---p 00007000 08:16 3026931 /home/thomas/qtsdk-2010.05/qt/plugins/imageformats/libqgif.so
7fffe08c3000-7fffe08c4000 rw-p 00007000 08:16 3026931 /home/thomas/qtsdk-2010.05/qt/plugins/imageformats/libqgif.so
7fffe08c4000-7fffe08c8000 r-xp 00000000 08:16 4333843 /usr/lib/kde4/plugins/imageformats/kimg_xview.so
7fffe08c8000-7fffe0ac7000 ---p 00004000 08:16 4333843 /usr/lib/kde4/plugins/imageformats/kimg_xview.so
7fffe0ac7000-7fffe0ac8000 r--p 00003000 08:16 4333843 /usr/lib/kde4/plugins/imageformats/kimg_xview.so
7fffe0ac8000-7fffe0ac9000 rw-p 00004000 08:16 4333843 /usr/lib/kde4/plugins/imageformats/kimg_xview.so
7fffe0ac9000-7fffe0ad8000 r-xp 00000000 08:16 4333847 /usr/lib/kde4/plugins/imageformats/kimg_xcf.so
7fffe0ad8000-7fffe0cd7000 ---p 0000f000 08:16 4333847 /usr/lib/kde4/plugins/imageformats/kimg_xcf.so
7fffe0cd7000-7fffe0cd8000 r--p 0000e000 08:16 4333847 /usr/lib/kde4/plugins/imageformats/kimg_xcf.so
7fffe0cd8000-7fffe0cd9000 rw-p 0000f000 08:16 4333847 /usr/lib/kde4/plugins/imageformats/kimg_xcf.so
7fffe0cd9000-7fffe0cdd000 rw-p 00000000 00:00 0 
7fffe0cdd000-7fffe0ce2000 r-xp 00000000 08:16 4333825 /usr/lib/kde4/plugins/imageformats/kimg_tga.so
7fffe0ce2000-7fffe0ee1000 ---p 00005000 08:16 4333825 /usr/lib/kde4/plugins/imageformats/kimg_tga.so
7fffe0ee1000-7fffe0ee2000 r--p 00004000 08:16 4333825 /usr/lib/kde4/plugins/imageformats/kimg_tga.so
7fffe0ee2000-7fffe0ee3000 rw-p 00005000 08:16 4333825 /usr/lib/kde4/plugins/imageformats/kimg_tga.so
7fffe0ee3000-7fffe0eec000 r-xp 00000000 08:16 4333822 /usr/lib/kde4/plugins/imageformats/kimg_rgb.so
7fffe0eec000-7fffe10ec000 ---p 00009000 08:16 4333822 /usr/lib/kde4/plugins/imageformats/kimg_rgb.so
7fffe10ec000-7fffe10ed000 r--p 00009000 08:16 4333822 /usr/lib/kde4/plugins/imageformats/kimg_rgb.so
7    fffe10ed000-7fffe10ee000 rw-p 0000a000 08:16 4333822 /usr/lib/kde4/plugins/imageformats/kimg_rgb.so
7fffe10ee000-7fffe10f3000 r-xp 00000000 08:16 4333846 /usr/lib/kde4/plugins/imageformats/kimg_ras.so
7fffe10f3000-7fffe12f2000 ---p 00005000 08:16 4333846

the rest I had to cut off


I'd recommend breaking the problem into two steps. Instead of using QTextBrowser::setSource, read the contents of the file manually with QFile and then set the contents of the browser to that QString using QTextEdit::setHtml. This allows you to check that the filename returned from your database is valid, that the HTML contents are valid (by inspecting the QString read from the QFile) and that construction of the QUrl and search path used by QTextBrowser::setSource is not an issue. That approach should turn up the issue and allow use of QTextBrowser::setSource again after it is resolved.

The stack dump seems to imply that a stray pointer is trying to be released since free is that last function in the trace. However, that could be deep in the Qt sources. The approach above may reach a solution faster than sorting through that large code base.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜