CodeBlocks wxWidgets-3.2.2.1编译错误

huangapple go评论149阅读模式
英文:

CodeBlocks wxWidgets-3.2.2.1 compile error

问题

情况

我正在尝试学习一些C++,并且正在使用IDE Code::Blocks 20.03 32位版(=C::B)、wxWidgets-3.2.2.1和GNU GCC编译器。

我使用wxSmith创建了一个带有wxFrame的GUI。在其中,我添加了一些其他组件(例如:wxSplitterWindows、wxAuiManagers、wxPanes、复选框、文本框等等)。
以下截图显示了主要的树结构:

CodeBlocks wxWidgets-3.2.2.1编译错误

C::B自动生成了GUI的相关代码,其中在文件splitter.h中,C::B生成了以下函数声明:

void Initialize(wxWindow *window);

而在文件dlgMain.cpp中,C::B生成了以下代码:

SplitterWindow->Initialize(AuiManager);

在分隔窗口组件中,我还以图形方式创建了一些AuiManagers。对于它们,IDE C::B自动创建了类似以下的代码,当然会根据需要更改变量名:

AuiManager = new wxAuiManager(SplitterWindow, wxAUI_MGR_ALLOW_ACTIVE_PANE|wxAUI_MGR_DEFAULT);

对于其中一些AuiManagers,我还创建了一些面板,并且C::B根据需要自动更改变量名生成了以下代码:

AuiManager->AddPane(Panel3, wxAuiPaneInfo().Name(_T("PaneName3")).DefaultPane().Caption(_("3) Caption of the Pane 3 (Auto Sorted Alphanumerically)")).CaptionVisible().MaximizeButton().CloseButton(false).Position(2).Center().Floatable(false).Movable(false).PaneBorder(false));
AuiManager->Update();

当然,窗口框架要复杂得多,正如您所预期的,它包含多个文件和几千行的总代码。

问题

当我编译项目时,编译器返回了一些错误,如下所示:

[文件路径]dlgMain.cpp [行号] 错误:没有与'wxSplitterWindow::Initialize(wxAuiManager*&)'匹配的函数调用
[文件路径]splitter.h [行号]  注释:候选项为:'void wxSplitterWindow::Initialize(wxWindow*)'
[文件路径]splitter.h [行号]  注释:参数1无法从'wxAuiManager*'转换为'wxWindow*'

总共有2个错误,分别对应以下代码行,由C::B编译器在"构建消息"选项卡中指示:

590: SplitterWindowSxVar->Initialize(AuiManagerSxVar);
1253: SplitterWindowDxVar->Initialize(AuiManagerDxVar);

这些错误出现在dlgMain.cpp文件中(这个文件是项目的一部分),它们调用了如下代码:

102: void Initialize(wxWindow *window);

该代码位于splitter.h文件中。

CodeBlocks wxWidgets-3.2.2.1编译错误

最后一个文件不是我的项目的一部分,而是来自wxWidgets的C++头文件,存储在以下路径中:

C:\wxWidgets-3.2.2.1\include\wx\generic\splitter.h

我没有手动创建以上任何代码:在使用图形设计器wxSmith插入组件到框架中时,C::B自动生成了所有内容。

我已经尝试过的方法

我将以下行:

void Initialize(wxWindow *window);

更改为:

void Initialize(wxAuiManager *window);

但没有成功,所以我返回了原始代码。

我还尝试找到

void Initialize(wxWindow *window);

的实现,但没有成功:我只能找到上面的一行,我认为这应该是声明,但没有实现的迹象。

我还从dlgMain.cpp文件中删除了以下行:

SplitterWindow->Initialize(AuiManager);

在删除后,项目可以编译并正确执行,没有错误,但一旦文件因任何原因而被更新或关闭并重新打开,C::B会自动再次生成我删除的代码行,因此错误会再次显示出来。

可能有帮助的一些截图

CodeBlocks wxWidgets-3.2.2.1编译错误
CodeBlocks wxWidgets-3.2.2.1编译错误
CodeBlocks wxWidgets-3.2.2.1编译错误

我删除的行被左侧的红色矩形指示,其中包含行号。但C::B会自动重新生成它们,如前所述。

问题:

  1. 编译时显示的错误是什么意思?
  2. 为什么我删除生成错误的代码行后,C::B在更新或关闭并重新打开项目时会自动重新生成它们?
  3. 为什么C::B会自动生成在编译时生成错误的代码?
  4. 我应该怎么做才能彻底摆脱这个错误?
英文:

Situation

I am trying to learn a bit of C++ and I am using the IDE Code::Blocks 20.03 32bit (=C::B), wxWidgets-3.2.2.1 and GNU GCC compiler.

I crated a GUI with wxSmith adding wxFrame. Inside it I added some other components (ex: wxSplitterWindows, wxAuiManagers, wxPanes, Checkboxes, textboxes and more).
The following screenshot shows the main tree structure:

CodeBlocks wxWidgets-3.2.2.1编译错误

C::B on its own generated the relative code of the GUI and among the other lines of code, into the file splitter.h, C::B generated the following function declaration:

void Initialize(wxWindow *window);

and into the file dlgMain.cpp C::B generated the following code:

SplitterWindow->Initialize(AuiManager);

Into the splitter window components I also created Graphically some AuiManagers. For them the IDE C::B automatically created code like the following, of course changing the variable names for each of them:

AuiManager = new wxAuiManager(SplitterWindow, wxAUI_MGR_ALLOW_ACTIVE_PANE|wxAUI_MGR_DEFAULT);

Into some of them I've also created some panels and C::B crated the code as follows also changing automatically the var names as it needed:

AuiManager->AddPane(Panel3, wxAuiPaneInfo().Name(_T("PaneName3")).DefaultPane().Caption(_("3) Caption of the Pane 3 (Auto Sorted Alphanumerically)")).CaptionVisible().MaximizeButton().CloseButton(false).Position(2).Center().Floatable(false).Movable(false).PaneBorder(false));
AuiManager->Update();

The Frame is much more complex of course and has as you can expect multiple files and some thousands lines of total code.

The problem

When I compile the project the compiler returns a couple of errors like the following for :

[filepath]dlgMain.cpp [row number] error: no matching function for call to 'wxSplitterWindow::Initialize(wxAuiManager*&)'
[filepath]splitter.h [row number]  note: candidate: 'void wxSplitterWindow::Initialize(wxWindow*)'
[filepath]splitter.h [row number]  note: no known conversion for argument 1 from 'wxAuiManager*' to 'wxWindow*'

The errors are 2 in total one for each of the following lines of code that C::B compiler indicates into the Built Messages Tab page:

590: SplitterWindowSxVar->Initialize(AuiManagerSxVar);
1253: SplitterWindowDxVar->Initialize(AuiManagerDxVar);

They are contained into the file dlgMain.cpp (a file that is part of the project)

they call the row

102: void Initialize(wxWindow *window);

contained into the file splitter.h

CodeBlocks wxWidgets-3.2.2.1编译错误

This last file is not part of my project but it is a c++ header file from wxWidgets and it is stored into the following path:

C:\wxWidgets-3.2.2.1\include\wx\generic\splitter.h

I did not create any of the above code manually: C::B created everything automatically while I inserted components into the Frame using the graphic designer wxSmith.

What I have tried:

I changed the line

void Initialize(wxWindow *window);

to

void Initialize(wxAuiManager *window);

without any success so I returned back to the original code.

I also tried to find the implementation of

void Initialize(wxWindow *window);

with no success: I can find just the above line that I suppose should be the declaration, but no track of the implementation itself.

I also deleted the row

SplitterWindow->Initialize(AuiManager);

from the dlgMain.cpp file: after the deletion, the project compiles and executes correctly whit no errors, but the line of code I deleted is regenerated automatically by C::B as soon as the file is updated or closed and reopened for any reason, so the error shows again right after.

Some screenshots that I hope can be helpful

CodeBlocks wxWidgets-3.2.2.1编译错误
CodeBlocks wxWidgets-3.2.2.1编译错误
CodeBlocks wxWidgets-3.2.2.1编译错误

The lines I delete are those indicated by the red rectangle on the left sides, where are the row numbers. But C::B recreates them automatically as already described.

Questions:

  1. What is the meaning of the error shown at compile time?
  2. Why the line of code that generates the error is regenerated automatically by C::B after I delete it and the project is updated or closed and reopened?
  3. Why C::B generates automatically code that generates errors when compiling?
  4. What do I do to get rid of the error once and for all?

答案1

得分: 1

你遇到的错误很容易理解:wxSplitterWindow::Initialize() 需要一个窗口,而你尝试传递的是 wxAuiManager,它根本不是一个窗口,而是一个用于管理其关联窗口内浮动/可停靠窗格的东西。令人惊讶的是 Code::Blocks 允许你将其用作“组件”,但这实际上没有意义,你根本不应该这样做。

要提出你应该实际做什么的建议会有点困难,因为不清楚你想要做什么。将 AUI 窗格放入 wxSplitterWindow 内并不是很有意义,因为 AUI 允许你做的远不止调整窗口大小,所以也许你根本不需要分隔器?

英文:

The error you're getting is simple to understand: wxSplitterWindow::Initialize() requires a window and you're trying to pass it wxAuiManager which is not a window at all, it's something that manages floating/dockable panes inside the window associated with it. It's surprising that C::B allows you to use it as a "component" but this really doesn't make sense and you simply shouldn't do it.

It's a bit harder to suggest what should you actually do instead because it's not clear what would you like to do. Putting AUI panes inside wxSplitterWindow doesn't make much sense because AUI allows you to do much more than just resize the windows, so perhaps you just don't need the splitter at all?

huangapple
  • 本文由 发表于 2023年6月22日 09:22:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/76528094.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定